{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Example 7: Rotational barrier prediction in KRAS inhibitors\n",
    "\n",
    "## Objective\n",
    "The objective of this task is to use the `molli` workflow to transition from `.CDXML` molecular drawings to full-fledged 3D structures with subsequent CREST//GFN2-XTB conformer generation, ORCA equilibrium structure minimization, as well as ORCA relaxed surface scan.\n",
    "This workflow is useful to assess semi-quantitatively the possibility of hindered rotation in a number of molecules (see e. g. [*J. Med. Chem.* **2020**, *63*, 1, 52](https://doi.org/10.1021/acs.jmedchem.9b01180))\n",
    "\n",
    "## Prerequisites\n",
    "- `molli` installation\n",
    "- `pandas` installation (it is NOT a dependency of molli and must be installed separately)\n",
    "- `OpenBabel` installation (it is NOT a dependency of molli and must be installed separately)\n",
    "    Note: if you experience problems with openbabel refusing to optimize the structures, do not forget to set the `BABEL_DATADIR` environment variable to point to a valid location with openbabel data files. With conda installations, it seems to be consistently pointing to `$CONDA_PREFIX/share/openbabel`\n",
    "- `barriers.csv` file that has the experimental rotational barriers listed\n",
    "- `cladosporin.cdxml` file that contains the structural drawings\n",
    "\n",
    "## Methods\n",
    "\n",
    "### Conformer generation\n",
    "Rotational barrier profiles are generated using b97-3c method, as reported by Grimme et al."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import molli as ml\n",
    "from molli.external import openbabel\n",
    "from math import degrees\n",
    "\n",
    "import pandas as pd\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from scipy.signal import find_peaks\n",
    "\n",
    "# This configures on-screen preview of molecules\n",
    "ml.visual.configure(bgcolor=\"black\", theme=\"dark\", width=500)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 1. `CDXML` Parsing\n",
    "\n",
    "In this step, all of the molecules are read from the CDXML file and converted into their 3D versions.\n",
    "This can be done from both the command line interface, but for the sake of exercise, this workflow will show the script that utilizes the key function of `ml.Molecule.join(...)`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To make sure that the parsing step was successful, we will perform a basic inspection of the resulting `.mlib` file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dihedral 117.02 for Molecule(name='23', formula='C28 H29 Cl1 F1 N5 O2')\n",
      "Dihedral 113.62 for Molecule(name='25', formula='C27 H27 Cl1 F1 N5 O2')\n",
      "Dihedral 134.54 for Molecule(name='28', formula='C24 H24 Cl1 F1 N6 O2 S1')\n",
      "Dihedral 144.75 for Molecule(name='27', formula='C24 H25 Cl1 F1 N7 O2')\n",
      "Dihedral 131.87 for Molecule(name='18', formula='C27 H27 Cl1 F1 N5 O2')\n",
      "Dihedral 128.08 for Molecule(name='29', formula='C25 H27 Cl1 F1 N7 O2')\n",
      "Dihedral 111.87 for Molecule(name='24', formula='C28 H29 Cl1 F1 N5 O2')\n",
      "Dihedral 139.62 for Molecule(name='26', formula='C26 H26 Cl1 F1 N6 O2')\n",
      "Dihedral 126.61 for Molecule(name='22', formula='C27 H25 Cl1 F1 N5 O2')\n"
     ]
    }
   ],
   "source": [
    "cdxf = ml.CDXMLFile(\"rot_barrier.cdxml\")\n",
    "core = cdxf[\"core\"]\n",
    "core_ap = core.get_attachment_points()[0]\n",
    "names = set(cdxf.keys())\n",
    "names.remove(\"core\")\n",
    "core.add_implicit_hydrogens()\n",
    "\n",
    "# This is the destination \n",
    "lib = ml.MoleculeLibrary(\"kras_inhibitors.mlib\", overwrite=True, readonly=False)\n",
    "\n",
    "with lib.writing():\n",
    "    for n in names:\n",
    "        sub = cdxf[n]\n",
    "        sub_ap = sub.get_attachment_points()[0]\n",
    "        \n",
    "        mol = ml.Molecule.join(\n",
    "            core,\n",
    "            sub,\n",
    "            core_ap,\n",
    "            sub_ap,\n",
    "            name=n,\n",
    "        )\n",
    "\n",
    "        mol.add_implicit_hydrogens()\n",
    "\n",
    "        openbabel.obabel_optimize(\n",
    "            mol,\n",
    "            ff=\"MMFF94\",\n",
    "            coord_displace=0.01,\n",
    "            inplace=True,\n",
    "        )\n",
    "\n",
    "        # just a little extra: calculate the preliminary dihedral angle)\n",
    "        d = mol.dihedral(\"1\", \"2\", \"3\", \"4\")\n",
    "        print(f\"Dihedral {degrees(d):0.2f} for {mol}\")\n",
    "\n",
    "        lib[n] = mol"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/3dmoljs_load.v0": "<div id=\"3dmolviewer_17296333558883967\"  style=\"position: relative; width: 100%; height: 500px;\">\n        <p id=\"3dmolwarning_17296333558883967\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n        </div>\n<script>\n\nvar loadScriptAsync = function(uri){\n  return new Promise((resolve, reject) => {\n    //this is to ignore the existence of requirejs amd\n    var savedexports, savedmodule;\n    if (typeof exports !== 'undefined') savedexports = exports;\n    else exports = {}\n    if (typeof module !== 'undefined') savedmodule = module;\n    else module = {}\n\n    var tag = document.createElement('script');\n    tag.src = uri;\n    tag.async = true;\n    tag.onload = () => {\n        exports = savedexports;\n        module = savedmodule;\n        resolve();\n    };\n  var firstScriptTag = document.getElementsByTagName('script')[0];\n  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n});\n};\n\nif(typeof $3Dmolpromise === 'undefined') {\n$3Dmolpromise = null;\n  $3Dmolpromise = loadScriptAsync('https://cdnjs.cloudflare.com/ajax/libs/3Dmol/2.0.4/3Dmol-min.js');\n}\n\nvar viewer_17296333558883967 = null;\nvar warn = document.getElementById(\"3dmolwarning_17296333558883967\");\nif(warn) {\n    warn.parentNode.removeChild(warn);\n}\n$3Dmolpromise.then(function() {\nviewer_17296333558883967 = $3Dmol.createViewer(document.getElementById(\"3dmolviewer_17296333558883967\"),{backgroundColor:\"white\"});\nviewer_17296333558883967.zoomTo();\n\tviewer_17296333558883967.addModel(\"@<TRIPOS>MOLECULE\\n22\\n61 66 0 0 0\\nSMALL\\nNO_CHARGES\\n\\n@<TRIPOS>ATOM\\n1 None -1.1179 3.6990 -0.8323 C\\n2 None -1.2350 2.3551 -0.4980 C\\n3 1 -0.0810 1.6210 -0.2604 C\\n4 None 1.1237 2.2387 -0.0635 N\\n5 None 1.2059 3.5999 -0.2193 C\\n6 None 0.1165 4.3325 -0.7066 C\\n7 None -2.5252 1.6262 -0.4356 C\\n8 None -2.5202 0.3419 -0.6266 N\\n9 None -1.3586 -0.3610 -0.8074 C\\n10 2 -0.1811 0.2076 -0.3177 N\\n11 None -1.3887 -1.4522 -1.3654 O\\n12 None -3.7524 2.2523 -0.1535 N\\n13 None -3.8912 3.4387 0.7256 C\\n14 None -5.1979 4.2049 0.4142 C\\n15 None -6.4047 3.3731 0.5330 N\\n16 None -6.2583 2.1913 -0.3354 C\\n17 None -4.9708 1.3692 -0.0699 C\\n18 None 0.2138 5.9725 -1.2398 Cl\\n19 None 2.5261 4.1780 0.1193 C\\n20 None 3.7359 3.5716 -0.2615 C\\n21 None 4.9792 4.1562 -0.0064 C\\n22 None 5.0516 5.3620 0.6832 C\\n23 None 3.8800 5.9595 1.1342 C\\n24 None 2.6454 5.3627 0.8654 C\\n25 None 3.7674 2.3537 -0.8857 O\\n26 None 1.5524 5.9499 1.3786 F\\n27 None -5.0404 0.6460 1.2840 C\\n28 None -1.9761 4.2484 -1.2078 H\\n29 None -3.8765 3.1256 1.7759 H\\n30 None -3.0706 4.1465 0.6178 H\\n31 None -5.2888 5.0510 1.1038 H\\n32 None -5.1438 4.6212 -0.6000 H\\n33 None -7.2180 3.9084 0.2302 H\\n34 None -7.1357 1.5485 -0.1988 H\\n35 None -6.2650 2.5174 -1.3833 H\\n36 None -4.9253 0.6131 -0.8639 H\\n37 None 5.8881 3.6567 -0.3329 H\\n38 None 6.0166 5.8184 0.8868 H\\n39 None 3.9144 6.8857 1.7003 H\\n40 None 2.9452 1.8930 -0.6142 H\\n41 None -4.1191 0.0942 1.4962 H\\n42 None -5.8669 -0.0723 1.2903 H\\n43 None -5.2025 1.3369 2.1176 H\\n44 3 1.0026 -0.5821 -0.3055 C\\n45 4 1.1477 -1.6224 0.6511 C\\n46 None 2.3502 -2.3583 0.6145 C\\n47 None 3.3413 -2.1168 -0.3401 C\\n48 None 3.1583 -1.1254 -1.2939 C\\n49 None 1.9911 -0.3668 -1.2827 C\\n50 None 0.1137 -1.8940 1.7362 C\\n51 None -1.1295 -2.6971 1.4229 C\\n52 None -0.0855 -3.2802 2.3176 C\\n53 None 2.5259 -3.1391 1.3514 H\\n54 None 4.2520 -2.7102 -0.3376 H\\n55 None 3.9210 -0.9417 -2.0461 H\\n56 None 1.8502 0.3857 -2.0548 H\\n57 None -0.0158 -1.0765 2.4441 H\\n58 None -2.0657 -2.3711 1.8610 H\\n59 None -1.2412 -3.1485 0.4426 H\\n60 None -0.3152 -3.3619 3.3735 H\\n61 None 0.4677 -4.1249 1.9237 H\\n@<TRIPOS>BOND\\n1 1 2 2\\n2 2 3 1\\n3 3 4 2\\n4 4 5 1\\n5 5 6 2\\n6 6 1 1\\n7 2 7 1\\n8 7 8 2\\n9 8 9 1\\n10 9 10 1\\n11 10 3 1\\n12 9 11 2\\n13 7 12 1\\n14 12 13 1\\n15 13 14 1\\n16 14 15 1\\n17 15 16 1\\n18 16 17 1\\n19 17 12 1\\n20 6 18 1\\n21 5 19 1\\n22 19 20 2\\n23 20 21 1\\n24 21 22 2\\n25 22 23 1\\n26 23 24 2\\n27 24 19 1\\n28 20 25 1\\n29 24 26 1\\n30 17 27 1\\n31 1 28 1\\n32 13 29 1\\n33 13 30 1\\n34 14 31 1\\n35 14 32 1\\n36 15 33 1\\n37 16 34 1\\n38 16 35 1\\n39 17 36 1\\n40 21 37 1\\n41 22 38 1\\n42 23 39 1\\n43 25 40 1\\n44 27 41 1\\n45 27 42 1\\n46 27 43 1\\n47 44 45 2\\n48 45 46 1\\n49 46 47 2\\n50 47 48 1\\n51 48 49 2\\n52 49 44 1\\n53 45 50 1\\n54 50 51 1\\n55 51 52 1\\n56 52 50 1\\n57 10 44 1\\n58 46 53 1\\n59 47 54 1\\n60 48 55 1\\n61 49 56 1\\n62 50 57 1\\n63 51 58 1\\n64 51 59 1\\n65 52 60 1\\n66 52 61 1\\n\\n\",\"mol2\");\n\tviewer_17296333558883967.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n\tviewer_17296333558883967.setHoverable({},true,\"\\n        function(atom,viewer,event,container) {\\n            if(!atom.label) {\\n                atom.label = viewer.addLabel(atom.elem + '(' + atom.index + ')', {position: atom, backgroundColor: 'silver', fontColor:'black'});\\n            }\\n        }\\n        \",\"\\n        function(atom,viewer) { \\n            if(atom.label) {\\n                viewer.removeLabel(atom.label);\\n                delete atom.label;\\n            }\\n        }\\n        \");\n\tviewer_17296333558883967.zoomTo();\n\tviewer_17296333558883967.setBackgroundColor(\"black\");\nviewer_17296333558883967.render();\n});\n</script>",
      "text/html": [
       "<div id=\"3dmolviewer_17296333558883967\"  style=\"position: relative; width: 100%; height: 500px;\">\n",
       "        <p id=\"3dmolwarning_17296333558883967\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n",
       "        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n",
       "        </div>\n",
       "<script>\n",
       "\n",
       "var loadScriptAsync = function(uri){\n",
       "  return new Promise((resolve, reject) => {\n",
       "    //this is to ignore the existence of requirejs amd\n",
       "    var savedexports, savedmodule;\n",
       "    if (typeof exports !== 'undefined') savedexports = exports;\n",
       "    else exports = {}\n",
       "    if (typeof module !== 'undefined') savedmodule = module;\n",
       "    else module = {}\n",
       "\n",
       "    var tag = document.createElement('script');\n",
       "    tag.src = uri;\n",
       "    tag.async = true;\n",
       "    tag.onload = () => {\n",
       "        exports = savedexports;\n",
       "        module = savedmodule;\n",
       "        resolve();\n",
       "    };\n",
       "  var firstScriptTag = document.getElementsByTagName('script')[0];\n",
       "  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n",
       "});\n",
       "};\n",
       "\n",
       "if(typeof $3Dmolpromise === 'undefined') {\n",
       "$3Dmolpromise = null;\n",
       "  $3Dmolpromise = loadScriptAsync('https://cdnjs.cloudflare.com/ajax/libs/3Dmol/2.0.4/3Dmol-min.js');\n",
       "}\n",
       "\n",
       "var viewer_17296333558883967 = null;\n",
       "var warn = document.getElementById(\"3dmolwarning_17296333558883967\");\n",
       "if(warn) {\n",
       "    warn.parentNode.removeChild(warn);\n",
       "}\n",
       "$3Dmolpromise.then(function() {\n",
       "viewer_17296333558883967 = $3Dmol.createViewer(document.getElementById(\"3dmolviewer_17296333558883967\"),{backgroundColor:\"white\"});\n",
       "viewer_17296333558883967.zoomTo();\n",
       "\tviewer_17296333558883967.addModel(\"@<TRIPOS>MOLECULE\\n22\\n61 66 0 0 0\\nSMALL\\nNO_CHARGES\\n\\n@<TRIPOS>ATOM\\n1 None -1.1179 3.6990 -0.8323 C\\n2 None -1.2350 2.3551 -0.4980 C\\n3 1 -0.0810 1.6210 -0.2604 C\\n4 None 1.1237 2.2387 -0.0635 N\\n5 None 1.2059 3.5999 -0.2193 C\\n6 None 0.1165 4.3325 -0.7066 C\\n7 None -2.5252 1.6262 -0.4356 C\\n8 None -2.5202 0.3419 -0.6266 N\\n9 None -1.3586 -0.3610 -0.8074 C\\n10 2 -0.1811 0.2076 -0.3177 N\\n11 None -1.3887 -1.4522 -1.3654 O\\n12 None -3.7524 2.2523 -0.1535 N\\n13 None -3.8912 3.4387 0.7256 C\\n14 None -5.1979 4.2049 0.4142 C\\n15 None -6.4047 3.3731 0.5330 N\\n16 None -6.2583 2.1913 -0.3354 C\\n17 None -4.9708 1.3692 -0.0699 C\\n18 None 0.2138 5.9725 -1.2398 Cl\\n19 None 2.5261 4.1780 0.1193 C\\n20 None 3.7359 3.5716 -0.2615 C\\n21 None 4.9792 4.1562 -0.0064 C\\n22 None 5.0516 5.3620 0.6832 C\\n23 None 3.8800 5.9595 1.1342 C\\n24 None 2.6454 5.3627 0.8654 C\\n25 None 3.7674 2.3537 -0.8857 O\\n26 None 1.5524 5.9499 1.3786 F\\n27 None -5.0404 0.6460 1.2840 C\\n28 None -1.9761 4.2484 -1.2078 H\\n29 None -3.8765 3.1256 1.7759 H\\n30 None -3.0706 4.1465 0.6178 H\\n31 None -5.2888 5.0510 1.1038 H\\n32 None -5.1438 4.6212 -0.6000 H\\n33 None -7.2180 3.9084 0.2302 H\\n34 None -7.1357 1.5485 -0.1988 H\\n35 None -6.2650 2.5174 -1.3833 H\\n36 None -4.9253 0.6131 -0.8639 H\\n37 None 5.8881 3.6567 -0.3329 H\\n38 None 6.0166 5.8184 0.8868 H\\n39 None 3.9144 6.8857 1.7003 H\\n40 None 2.9452 1.8930 -0.6142 H\\n41 None -4.1191 0.0942 1.4962 H\\n42 None -5.8669 -0.0723 1.2903 H\\n43 None -5.2025 1.3369 2.1176 H\\n44 3 1.0026 -0.5821 -0.3055 C\\n45 4 1.1477 -1.6224 0.6511 C\\n46 None 2.3502 -2.3583 0.6145 C\\n47 None 3.3413 -2.1168 -0.3401 C\\n48 None 3.1583 -1.1254 -1.2939 C\\n49 None 1.9911 -0.3668 -1.2827 C\\n50 None 0.1137 -1.8940 1.7362 C\\n51 None -1.1295 -2.6971 1.4229 C\\n52 None -0.0855 -3.2802 2.3176 C\\n53 None 2.5259 -3.1391 1.3514 H\\n54 None 4.2520 -2.7102 -0.3376 H\\n55 None 3.9210 -0.9417 -2.0461 H\\n56 None 1.8502 0.3857 -2.0548 H\\n57 None -0.0158 -1.0765 2.4441 H\\n58 None -2.0657 -2.3711 1.8610 H\\n59 None -1.2412 -3.1485 0.4426 H\\n60 None -0.3152 -3.3619 3.3735 H\\n61 None 0.4677 -4.1249 1.9237 H\\n@<TRIPOS>BOND\\n1 1 2 2\\n2 2 3 1\\n3 3 4 2\\n4 4 5 1\\n5 5 6 2\\n6 6 1 1\\n7 2 7 1\\n8 7 8 2\\n9 8 9 1\\n10 9 10 1\\n11 10 3 1\\n12 9 11 2\\n13 7 12 1\\n14 12 13 1\\n15 13 14 1\\n16 14 15 1\\n17 15 16 1\\n18 16 17 1\\n19 17 12 1\\n20 6 18 1\\n21 5 19 1\\n22 19 20 2\\n23 20 21 1\\n24 21 22 2\\n25 22 23 1\\n26 23 24 2\\n27 24 19 1\\n28 20 25 1\\n29 24 26 1\\n30 17 27 1\\n31 1 28 1\\n32 13 29 1\\n33 13 30 1\\n34 14 31 1\\n35 14 32 1\\n36 15 33 1\\n37 16 34 1\\n38 16 35 1\\n39 17 36 1\\n40 21 37 1\\n41 22 38 1\\n42 23 39 1\\n43 25 40 1\\n44 27 41 1\\n45 27 42 1\\n46 27 43 1\\n47 44 45 2\\n48 45 46 1\\n49 46 47 2\\n50 47 48 1\\n51 48 49 2\\n52 49 44 1\\n53 45 50 1\\n54 50 51 1\\n55 51 52 1\\n56 52 50 1\\n57 10 44 1\\n58 46 53 1\\n59 47 54 1\\n60 48 55 1\\n61 49 56 1\\n62 50 57 1\\n63 51 58 1\\n64 51 59 1\\n65 52 60 1\\n66 52 61 1\\n\\n\",\"mol2\");\n",
       "\tviewer_17296333558883967.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n",
       "\tviewer_17296333558883967.setHoverable({},true,\"\\n        function(atom,viewer,event,container) {\\n            if(!atom.label) {\\n                atom.label = viewer.addLabel(atom.elem + '(' + atom.index + ')', {position: atom, backgroundColor: 'silver', fontColor:'black'});\\n            }\\n        }\\n        \",\"\\n        function(atom,viewer) { \\n            if(atom.label) {\\n                viewer.removeLabel(atom.label);\\n                delete atom.label;\\n            }\\n        }\\n        \");\n",
       "\tviewer_17296333558883967.zoomTo();\n",
       "\tviewer_17296333558883967.setBackgroundColor(\"black\");\n",
       "viewer_17296333558883967.render();\n",
       "});\n",
       "</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/3dmoljs_load.v0": "<script>\n            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n                \n                viewer_17296333558883967.render();\n            });\n            </script>",
      "text/html": [
       "<script>\n",
       "            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n",
       "                \n",
       "                viewer_17296333558883967.render();\n",
       "            });\n",
       "            </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/3dmoljs_load.v0": "<script>\n            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n                \tviewer_17296333558883967.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n\n                viewer_17296333558883967.render();\n            });\n            </script>",
      "text/html": [
       "<script>\n",
       "            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n",
       "                \tviewer_17296333558883967.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n",
       "\n",
       "                viewer_17296333558883967.render();\n",
       "            });\n",
       "            </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%mlib_view kras_inhibitors.mlib 22"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We will now import the molecule library into our python code. the success of this step will be demonstrated by rendering the parsing result of an arbitrary molecule. Give it a try and substitute the name with any names that were obtained in the inspect stage!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 2. XTB relaxed surface scan.\n",
    "\n",
    "In this step we will be attempting to generate the guess structure of the transition state of the hindered rotation by performing the *Relaxed Surface Scan* of the rotation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Submitting jobs: 0it [00:00, ?it/s]\n",
      "Waiting for jobs: 0it [00:00, ?it/s]\n",
      "Finalizing the calculations: 100%|███████████████| 9/9 [00:00<00:00, 180.65it/s]\n"
     ]
    }
   ],
   "source": [
    "# Jupyter does not play nice with the Thread parallelism, so we placed the workflow in a separate file.\n",
    "!python scan.py "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9 2 43 44 70.75379386832473\n",
      "Minima: [], maxima: [26] 255.47593799748057\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjsAAAGwCAYAAABPSaTdAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABkd0lEQVR4nO3dd3hT5d8G8PskbdK996C7ILTsWZW9FRUcoKigiIiCIiAKqIAKKKKgIG5BFAT9CY4XBdkIyCpUyi7QQksX3TttkvP+URqorKRNejLuz3XlojnnJLkzaL59zjMEURRFEBEREVkpmdQBiIiIiEyJxQ4RERFZNRY7REREZNVY7BAREZFVY7FDREREVo3FDhEREVk1FjtERERk1eykDmAOtFotMjMz4erqCkEQpI5DREREehBFEaWlpQgKCoJMdvP2GxY7ADIzMxEaGip1DCIiImqA9PR0hISE3HQ/ix0Arq6uAGpfLDc3N4nTEBERkT5KSkoQGhqq+x6/GRY7gO7UlZubG4sdIiIiC3O7LijsoExERERWjcUOERERWTUWO0RERGTVWOwQERGRVWOxQ0RERFaNxQ4RERFZNRY7REREZNVY7BAREZFVY7FDREREVo3FDhEREVk1FjtERGRetmwBWras/ZfICFjsEBGR+RBFYMYM4OTJ2n9FUepEZAVY7BARkfn46y/g4MHanw8erL1O1EgsdoiIyDyIIvDGG9DKar+atDIZ1DNmsnWHGo3FDhERmYcrrToyrRYAINNqYXc4ETuXfA+tlgUPNRyLHSIikp4oQvv669AI9b+W1IIMHvPfxojP/8GZnF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6X0+t+Qmppq6hxERNQIv/+bifNXWnVGJYRLHceidA73ri12zudz9JqVatRCoEREJD2NVsTH14zAYquOYbpEegG42m+HrI9exc67776L8vJyve5w//79HIJORNSEfj6cgfOXy+HuyBFYDdE21AMKuQy5pSqk5VdIHYdMQK9i58SJEwgLC8P48ePx559/4vLly7p9arUaR48exbJly5CQkIARI0bAzc3NZIGJiOiqymoNPvjrNABgQq9ouDrYS5zI8jjYy9E21AMAcCA1X9owZBJ6FTsrV67Etm3boNVqMXLkSAQEBEChUMDV1RVKpRLt2rXDN998g9GjR+PUqVO4++67TZ2biIgAfLMnFTklKgR7OHINrEboHFF7Kmv/eU4uaI30PrHbunVrfP755/jss89w9OhRpKWlobKyEj4+Pmjbti18fHxMmZOIiP4jv0yFT3ecAwBMG9gcDvZyiRNZri6RXli6HdjPmZStksG92ARBQJs2bdCmTRtT5CEiIj0t2XYWZSo14oLdMKR1kNRxLFr7Zp6QywRcKqpERmEFQjydpI5ERsTRWEREFigtrxzf77sAAJgx6A7IZJz5tzGclXaID3YHwHWyrBGLHSIiC/T+ptNQa0X0bO6LhGh2IzCGLuy3Y7VY7BARWZgjFwuxITkLggC8NqiF1HGshm6+nTQWO9aGxQ4RkQURRRHz/jgJAHiofQhaBHCqD2PpEOYFQQBS88qRW1IldRwyIoOLnRUrVqCigpMuERFJYfOJHBxMK4SDvQyT+8dKHcequDvao2VgbfG4j/12rIrBxc706dMREBCAMWPGYO/evabIREREN6DWaPHuxlMAgDF3RSDQ3VHiRNanS4Q3AE4uaG0MLnYyMjLw/fffo7CwEL169UKLFi3w3nvvITs72xT5iIjoirWH0nH+cjm8nBUY1yNK6jhWiZMLWieDix25XI777rsP69atQ3p6Op599lmsWrUKzZo1w3333Ydff/0VWq3WFFmJiGxWuUqNRZtrF/t8sXc03LgshEnUFTspuWXIL1NJnIaMpVEdlP38/HDnnXeiW7dukMlkSE5OxujRoxEVFYUdO3YYKSIREX3593nklakQ5u2Ex7pwWQhT8XJWINbfBQBwkK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O06tVuPQoUO666dPn0ZRURFatGihdx4iMh07qQMQke3q2bMnWrVqhXnz5mHp0qX4v//7P6xZswYjRoxAbGwsRFHE77//jj/++APLly8HAMyePRsVFRUYPHgwwsLCUFRUhI8//hg1NTXo16/fDR/n888/R1JSEoYOHYqoqChUVVVh5cqVOH78OJYsWQKgtmAqKyvD1q1b0aZNGzg5OSE2NhYjR47Ek08+iQ8++ADt2rVDXl4etm3bhvj4eAwePBgAYG9vj4kTJ+Ljjz+Gvb09JkyYgK5du6Jz585N80IS0a1J3WmIiGzDjYaei6Iorlq1SlQoFOLFixfFc+fOiWPHjhVjY2NFR0dH0cPDQ+zUqZO4fPly3fHbtm0TH3zwQTE0NFRUKBSiv7+/OHDgQPHvv/++6WMfPnxYfPzxx8WIiAhRqVSK3t7eYvfu3cXffvut3nHPPfec6O3tXW/oeXV1tfjmm2+K4eHhor29vRgQECAOHTpUPHr0qCiKVzs2//zzz2JkZKSoUCjE3r17i2lpaY1+zYjIOARRvMn4TiIiuq0VK1Zg0qRJKCoqkjoKEd0E++wQERGRVWOxQ0RERFaNp7GIiIjIqrFlh4iIiKwaix0iIiKyaix2iIiIyKqx2CEiIiKrxmKHiIiIrBqLHSIiIrJqLHaIiIjIqrHYISIiIqv2/9aptF49B0fKAAAAAElFTkSuQmCC",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "scan_lib = ml.ConformerLibrary(\"kras_inhibitors_scan.clib\")\n",
    "\n",
    "with scan_lib.reading():\n",
    "    ens = scan_lib[\"25\"]\n",
    "\n",
    "# nrg = [\n",
    "#     x[\"ORCA/SCF_Energy\"] + x[\"ORCA/VdW_Correction\"]\n",
    "#     for x in ens.attrib[\"conformer_attrib\"]\n",
    "# ]\n",
    "\n",
    "nrg = ens.attrib['XTB/Conformer_Energies']\n",
    "\n",
    "nrg_rel = 2625.5 * (nrg - np.min(nrg))\n",
    "\n",
    "idx = ens.get_atom_indices(\"2\", \"1\", \"3\", \"4\")\n",
    "print(*idx, np.degrees(ens[28].dihedral(*idx)))\n",
    "\n",
    "minima, _ = find_peaks(-nrg_rel, distance=10)\n",
    "maxima, _ = find_peaks(nrg_rel, distance=10, height=10)\n",
    "\n",
    "plt.plot(nrg_rel)\n",
    "plt.plot(minima, nrg_rel[minima], \"ob\")\n",
    "plt.plot(maxima, nrg_rel[maxima], \"^r\")\n",
    "plt.xlabel(\"RSS Step\")\n",
    "plt.ylabel(\"GFN2-XTB Relative energy (kJ/mol)\")\n",
    "print(f\"Minima: {minima}, maxima: {maxima}\", np.max(nrg_rel[maxima]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Approx. barrier 18:  125.8 kJ/mol   30.1 kcal/mol\n",
      "Approx. barrier 22:  127.5 kJ/mol   30.5 kcal/mol\n",
      "Approx. barrier 23:  162.3 kJ/mol   38.8 kcal/mol\n",
      "Approx. barrier 24:  203.4 kJ/mol   48.6 kcal/mol\n",
      "Approx. barrier 25:  246.9 kJ/mol   59.0 kcal/mol\n",
      "Approx. barrier 26:   81.1 kJ/mol   19.4 kcal/mol\n",
      "Approx. barrier 27:   57.9 kJ/mol   13.8 kcal/mol\n",
      "Approx. barrier 28:   38.1 kJ/mol    9.1 kcal/mol\n",
      "Approx. barrier 29:   69.3 kJ/mol   16.6 kcal/mol\n"
     ]
    }
   ],
   "source": [
    "with scan_lib.reading():\n",
    "    for k in sorted(scan_lib.keys()):\n",
    "        ens = scan_lib[k]\n",
    "        # nrg = [\n",
    "        #     x[\"ORCA/SCF_Energy\"] + x[\"ORCA/VdW_Correction\"]\n",
    "        #     for x in ens.attrib[\"conformer_attrib\"]\n",
    "        # ]\n",
    "        \n",
    "        nrg = ens.attrib['XTB/Conformer_Energies']\n",
    "        nrg_rel = 2625.5 * (nrg - np.min(nrg))\n",
    "\n",
    "        eq = 0\n",
    "        ts_min = np.max(nrg_rel)\n",
    "        barrier = ts_min - nrg_rel[eq]\n",
    "        print(f\"Approx. barrier {ens.name}: {barrier:6.1f} kJ/mol {barrier/4.184:6.1f} kcal/mol\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now that we have the approximate structures, we will write out equilibrium structure guesses in one library (`rb_eq_g0.mlib`), and our transition state structures --- into a separate one (`ts_eq_g0.mlib`)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "eq_lib = ml.MoleculeLibrary(\"rb_eq_g0.mlib\", readonly=False)\n",
    "ts_lib = ml.MoleculeLibrary(\"rb_ts_g0.mlib\", readonly=False)\n",
    "\n",
    "with scan_lib.reading(), eq_lib.writing(), ts_lib.writing():\n",
    "    for key, ens in scan_lib.items():\n",
    "        nrg = ens.attrib['XTB/Conformer_Energies']\n",
    "        nrg_rel = 2625.5 * (nrg - np.min(nrg))\n",
    "\n",
    "        eq1 = int(np.argmin(nrg_rel[:6]))\n",
    "        eq2 = int(np.argmin(nrg_rel[-6:]) + len(nrg_rel) - 6)\n",
    "        ts = int(np.argmax(nrg_rel))\n",
    "\n",
    "        eq_lib[key + \"_eq1\"] = ens[eq1]\n",
    "        eq_lib[key + \"_eq2\"] = ens[eq2]\n",
    "\n",
    "        ts_lib[key] = ens[ts]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/3dmoljs_load.v0": "<div id=\"3dmolviewer_17296333570683858\"  style=\"position: relative; width: 100%; height: 500px;\">\n        <p id=\"3dmolwarning_17296333570683858\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n        </div>\n<script>\n\nvar loadScriptAsync = function(uri){\n  return new Promise((resolve, reject) => {\n    //this is to ignore the existence of requirejs amd\n    var savedexports, savedmodule;\n    if (typeof exports !== 'undefined') savedexports = exports;\n    else exports = {}\n    if (typeof module !== 'undefined') savedmodule = module;\n    else module = {}\n\n    var tag = document.createElement('script');\n    tag.src = uri;\n    tag.async = true;\n    tag.onload = () => {\n        exports = savedexports;\n        module = savedmodule;\n        resolve();\n    };\n  var firstScriptTag = document.getElementsByTagName('script')[0];\n  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n});\n};\n\nif(typeof $3Dmolpromise === 'undefined') {\n$3Dmolpromise = null;\n  $3Dmolpromise = loadScriptAsync('https://cdnjs.cloudflare.com/ajax/libs/3Dmol/2.0.4/3Dmol-min.js');\n}\n\nvar viewer_17296333570683858 = null;\nvar warn = document.getElementById(\"3dmolwarning_17296333570683858\");\nif(warn) {\n    warn.parentNode.removeChild(warn);\n}\n$3Dmolpromise.then(function() {\nviewer_17296333570683858 = $3Dmol.createViewer(document.getElementById(\"3dmolviewer_17296333570683858\"),{backgroundColor:\"white\"});\nviewer_17296333570683858.zoomTo();\n\tviewer_17296333570683858.addModel(\"@<TRIPOS>MOLECULE\\n26\\n62 66 0 0 0\\nSMALL\\nNO_CHARGES\\n\\n@<TRIPOS>ATOM\\n1 None -1.2611 3.6787 -0.4433 C\\n2 None -1.3701 2.3147 -0.1791 C\\n3 1 -0.1542 1.5942 -0.0873 C\\n4 None 1.0180 2.2060 0.0336 N\\n5 None 1.1081 3.5227 -0.0666 C\\n6 None -0.0201 4.2865 -0.4153 C\\n7 None -2.5803 1.5086 -0.1294 C\\n8 None -2.5130 0.2349 -0.4282 N\\n9 None -1.3640 -0.4405 -0.5696 C\\n10 2 -0.1759 0.2369 -0.1213 N\\n11 None -1.2809 -1.5744 -0.9727 O\\n12 None -3.7830 2.0102 0.1807 N\\n13 None -4.0292 3.2405 0.8960 C\\n14 None -5.0406 4.0876 0.1223 C\\n15 None -6.2487 3.2976 -0.0075 N\\n16 None -5.9989 2.0926 -0.7776 C\\n17 None -4.9797 1.2094 -0.0439 C\\n18 None 0.1145 5.9386 -0.9028 Cl\\n19 None 2.4462 4.0970 0.1009 C\\n20 None 3.5670 3.4803 -0.4898 C\\n21 None 4.8106 4.1117 -0.4083 C\\n22 None 4.9677 5.2891 0.2903 C\\n23 None 3.8914 5.8647 0.9485 C\\n24 None 2.6579 5.2600 0.8403 C\\n25 None 3.5003 2.3282 -1.1613 O\\n26 None 1.6252 5.7901 1.5313 F\\n27 None -5.5543 0.6434 1.2523 C\\n28 None -2.1233 4.2635 -0.7219 H\\n29 None -4.4749 2.9884 1.8644 H\\n30 None -3.1027 3.7792 1.0791 H\\n31 None -5.2670 4.9972 0.6816 H\\n32 None -4.6129 4.3708 -0.8570 H\\n33 None -6.9925 3.8410 -0.4317 H\\n34 None -6.9364 1.5452 -0.8846 H\\n35 None -5.6072 2.3176 -1.7857 H\\n36 None -4.6746 0.3816 -0.6885 H\\n37 None 5.6461 3.6374 -0.8974 H\\n38 None 5.9391 5.7550 0.3469 H\\n39 None 3.9966 6.7603 1.5385 H\\n40 None 2.6514 1.8610 -1.0043 H\\n41 None -4.7623 0.1863 1.8396 H\\n42 None -6.2895 -0.1199 1.0153 H\\n43 None -6.0430 1.4212 1.8322 H\\n44 3 1.0258 -0.5130 -0.0454 C\\n45 4 1.1316 -1.5834 0.8468 C\\n46 None 2.3147 -2.3117 0.7829 C\\n47 None 3.3173 -1.9463 -0.0986 C\\n48 None 3.1160 -0.8281 -0.8892 C\\n49 None 1.9912 -0.1365 -0.8666 N\\n50 None 0.0620 -1.9239 1.8524 C\\n51 None 0.6277 -1.8576 3.2737 C\\n52 None -0.5317 -3.3013 1.5539 C\\n53 None 2.4541 -3.1645 1.4307 H\\n54 None 4.2360 -2.5083 -0.1590 H\\n55 None 3.8700 -0.4631 -1.5720 H\\n56 None -0.7423 -1.1853 1.7756 H\\n57 None 1.0753 -0.8835 3.4624 H\\n58 None 1.3861 -2.6206 3.4292 H\\n59 None -0.1692 -2.0179 3.9965 H\\n60 None 0.2281 -4.0757 1.6261 H\\n61 None -0.9459 -3.3066 0.5489 H\\n62 None -1.3258 -3.5268 2.2619 H\\n@<TRIPOS>BOND\\n1 1 2 2\\n2 2 3 1\\n3 3 4 2\\n4 4 5 1\\n5 5 6 2\\n6 6 1 1\\n7 2 7 1\\n8 7 8 2\\n9 8 9 1\\n10 9 10 1\\n11 10 3 1\\n12 9 11 2\\n13 7 12 1\\n14 12 13 1\\n15 13 14 1\\n16 14 15 1\\n17 15 16 1\\n18 16 17 1\\n19 17 12 1\\n20 6 18 1\\n21 5 19 1\\n22 19 20 2\\n23 20 21 1\\n24 21 22 2\\n25 22 23 1\\n26 23 24 2\\n27 24 19 1\\n28 20 25 1\\n29 24 26 1\\n30 17 27 1\\n31 1 28 1\\n32 13 29 1\\n33 13 30 1\\n34 14 31 1\\n35 14 32 1\\n36 15 33 1\\n37 16 34 1\\n38 16 35 1\\n39 17 36 1\\n40 21 37 1\\n41 22 38 1\\n42 23 39 1\\n43 25 40 1\\n44 27 41 1\\n45 27 42 1\\n46 27 43 1\\n47 44 45 2\\n48 45 46 1\\n49 46 47 2\\n50 47 48 1\\n51 48 49 2\\n52 49 44 1\\n53 50 51 1\\n54 50 52 1\\n55 45 50 1\\n56 10 44 1\\n57 46 53 1\\n58 47 54 1\\n59 48 55 1\\n60 50 56 1\\n61 51 57 1\\n62 51 58 1\\n63 51 59 1\\n64 52 60 1\\n65 52 61 1\\n66 52 62 1\\n\\n\",\"mol2\");\n\tviewer_17296333570683858.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n\tviewer_17296333570683858.setHoverable({},true,\"\\n        function(atom,viewer,event,container) {\\n            if(!atom.label) {\\n                atom.label = viewer.addLabel(atom.elem + '(' + atom.index + ')', {position: atom, backgroundColor: 'silver', fontColor:'black'});\\n            }\\n        }\\n        \",\"\\n        function(atom,viewer) { \\n            if(atom.label) {\\n                viewer.removeLabel(atom.label);\\n                delete atom.label;\\n            }\\n        }\\n        \");\n\tviewer_17296333570683858.zoomTo();\n\tviewer_17296333570683858.setBackgroundColor(\"black\");\nviewer_17296333570683858.render();\n});\n</script>",
      "text/html": [
       "<div id=\"3dmolviewer_17296333570683858\"  style=\"position: relative; width: 100%; height: 500px;\">\n",
       "        <p id=\"3dmolwarning_17296333570683858\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n",
       "        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n",
       "        </div>\n",
       "<script>\n",
       "\n",
       "var loadScriptAsync = function(uri){\n",
       "  return new Promise((resolve, reject) => {\n",
       "    //this is to ignore the existence of requirejs amd\n",
       "    var savedexports, savedmodule;\n",
       "    if (typeof exports !== 'undefined') savedexports = exports;\n",
       "    else exports = {}\n",
       "    if (typeof module !== 'undefined') savedmodule = module;\n",
       "    else module = {}\n",
       "\n",
       "    var tag = document.createElement('script');\n",
       "    tag.src = uri;\n",
       "    tag.async = true;\n",
       "    tag.onload = () => {\n",
       "        exports = savedexports;\n",
       "        module = savedmodule;\n",
       "        resolve();\n",
       "    };\n",
       "  var firstScriptTag = document.getElementsByTagName('script')[0];\n",
       "  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n",
       "});\n",
       "};\n",
       "\n",
       "if(typeof $3Dmolpromise === 'undefined') {\n",
       "$3Dmolpromise = null;\n",
       "  $3Dmolpromise = loadScriptAsync('https://cdnjs.cloudflare.com/ajax/libs/3Dmol/2.0.4/3Dmol-min.js');\n",
       "}\n",
       "\n",
       "var viewer_17296333570683858 = null;\n",
       "var warn = document.getElementById(\"3dmolwarning_17296333570683858\");\n",
       "if(warn) {\n",
       "    warn.parentNode.removeChild(warn);\n",
       "}\n",
       "$3Dmolpromise.then(function() {\n",
       "viewer_17296333570683858 = $3Dmol.createViewer(document.getElementById(\"3dmolviewer_17296333570683858\"),{backgroundColor:\"white\"});\n",
       "viewer_17296333570683858.zoomTo();\n",
       "\tviewer_17296333570683858.addModel(\"@<TRIPOS>MOLECULE\\n26\\n62 66 0 0 0\\nSMALL\\nNO_CHARGES\\n\\n@<TRIPOS>ATOM\\n1 None -1.2611 3.6787 -0.4433 C\\n2 None -1.3701 2.3147 -0.1791 C\\n3 1 -0.1542 1.5942 -0.0873 C\\n4 None 1.0180 2.2060 0.0336 N\\n5 None 1.1081 3.5227 -0.0666 C\\n6 None -0.0201 4.2865 -0.4153 C\\n7 None -2.5803 1.5086 -0.1294 C\\n8 None -2.5130 0.2349 -0.4282 N\\n9 None -1.3640 -0.4405 -0.5696 C\\n10 2 -0.1759 0.2369 -0.1213 N\\n11 None -1.2809 -1.5744 -0.9727 O\\n12 None -3.7830 2.0102 0.1807 N\\n13 None -4.0292 3.2405 0.8960 C\\n14 None -5.0406 4.0876 0.1223 C\\n15 None -6.2487 3.2976 -0.0075 N\\n16 None -5.9989 2.0926 -0.7776 C\\n17 None -4.9797 1.2094 -0.0439 C\\n18 None 0.1145 5.9386 -0.9028 Cl\\n19 None 2.4462 4.0970 0.1009 C\\n20 None 3.5670 3.4803 -0.4898 C\\n21 None 4.8106 4.1117 -0.4083 C\\n22 None 4.9677 5.2891 0.2903 C\\n23 None 3.8914 5.8647 0.9485 C\\n24 None 2.6579 5.2600 0.8403 C\\n25 None 3.5003 2.3282 -1.1613 O\\n26 None 1.6252 5.7901 1.5313 F\\n27 None -5.5543 0.6434 1.2523 C\\n28 None -2.1233 4.2635 -0.7219 H\\n29 None -4.4749 2.9884 1.8644 H\\n30 None -3.1027 3.7792 1.0791 H\\n31 None -5.2670 4.9972 0.6816 H\\n32 None -4.6129 4.3708 -0.8570 H\\n33 None -6.9925 3.8410 -0.4317 H\\n34 None -6.9364 1.5452 -0.8846 H\\n35 None -5.6072 2.3176 -1.7857 H\\n36 None -4.6746 0.3816 -0.6885 H\\n37 None 5.6461 3.6374 -0.8974 H\\n38 None 5.9391 5.7550 0.3469 H\\n39 None 3.9966 6.7603 1.5385 H\\n40 None 2.6514 1.8610 -1.0043 H\\n41 None -4.7623 0.1863 1.8396 H\\n42 None -6.2895 -0.1199 1.0153 H\\n43 None -6.0430 1.4212 1.8322 H\\n44 3 1.0258 -0.5130 -0.0454 C\\n45 4 1.1316 -1.5834 0.8468 C\\n46 None 2.3147 -2.3117 0.7829 C\\n47 None 3.3173 -1.9463 -0.0986 C\\n48 None 3.1160 -0.8281 -0.8892 C\\n49 None 1.9912 -0.1365 -0.8666 N\\n50 None 0.0620 -1.9239 1.8524 C\\n51 None 0.6277 -1.8576 3.2737 C\\n52 None -0.5317 -3.3013 1.5539 C\\n53 None 2.4541 -3.1645 1.4307 H\\n54 None 4.2360 -2.5083 -0.1590 H\\n55 None 3.8700 -0.4631 -1.5720 H\\n56 None -0.7423 -1.1853 1.7756 H\\n57 None 1.0753 -0.8835 3.4624 H\\n58 None 1.3861 -2.6206 3.4292 H\\n59 None -0.1692 -2.0179 3.9965 H\\n60 None 0.2281 -4.0757 1.6261 H\\n61 None -0.9459 -3.3066 0.5489 H\\n62 None -1.3258 -3.5268 2.2619 H\\n@<TRIPOS>BOND\\n1 1 2 2\\n2 2 3 1\\n3 3 4 2\\n4 4 5 1\\n5 5 6 2\\n6 6 1 1\\n7 2 7 1\\n8 7 8 2\\n9 8 9 1\\n10 9 10 1\\n11 10 3 1\\n12 9 11 2\\n13 7 12 1\\n14 12 13 1\\n15 13 14 1\\n16 14 15 1\\n17 15 16 1\\n18 16 17 1\\n19 17 12 1\\n20 6 18 1\\n21 5 19 1\\n22 19 20 2\\n23 20 21 1\\n24 21 22 2\\n25 22 23 1\\n26 23 24 2\\n27 24 19 1\\n28 20 25 1\\n29 24 26 1\\n30 17 27 1\\n31 1 28 1\\n32 13 29 1\\n33 13 30 1\\n34 14 31 1\\n35 14 32 1\\n36 15 33 1\\n37 16 34 1\\n38 16 35 1\\n39 17 36 1\\n40 21 37 1\\n41 22 38 1\\n42 23 39 1\\n43 25 40 1\\n44 27 41 1\\n45 27 42 1\\n46 27 43 1\\n47 44 45 2\\n48 45 46 1\\n49 46 47 2\\n50 47 48 1\\n51 48 49 2\\n52 49 44 1\\n53 50 51 1\\n54 50 52 1\\n55 45 50 1\\n56 10 44 1\\n57 46 53 1\\n58 47 54 1\\n59 48 55 1\\n60 50 56 1\\n61 51 57 1\\n62 51 58 1\\n63 51 59 1\\n64 52 60 1\\n65 52 61 1\\n66 52 62 1\\n\\n\",\"mol2\");\n",
       "\tviewer_17296333570683858.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n",
       "\tviewer_17296333570683858.setHoverable({},true,\"\\n        function(atom,viewer,event,container) {\\n            if(!atom.label) {\\n                atom.label = viewer.addLabel(atom.elem + '(' + atom.index + ')', {position: atom, backgroundColor: 'silver', fontColor:'black'});\\n            }\\n        }\\n        \",\"\\n        function(atom,viewer) { \\n            if(atom.label) {\\n                viewer.removeLabel(atom.label);\\n                delete atom.label;\\n            }\\n        }\\n        \");\n",
       "\tviewer_17296333570683858.zoomTo();\n",
       "\tviewer_17296333570683858.setBackgroundColor(\"black\");\n",
       "viewer_17296333570683858.render();\n",
       "});\n",
       "</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/3dmoljs_load.v0": "<script>\n            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n                \n                viewer_17296333570683858.render();\n            });\n            </script>",
      "text/html": [
       "<script>\n",
       "            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n",
       "                \n",
       "                viewer_17296333570683858.render();\n",
       "            });\n",
       "            </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/3dmoljs_load.v0": "<script>\n            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n                \tviewer_17296333570683858.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n\n                viewer_17296333570683858.render();\n            });\n            </script>",
      "text/html": [
       "<script>\n",
       "            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n",
       "                \tviewer_17296333570683858.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n",
       "\n",
       "                viewer_17296333570683858.render();\n",
       "            });\n",
       "            </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/3dmoljs_load.v0": "<div id=\"3dmolviewer_17296333570725398\"  style=\"position: relative; width: 100%; height: 500px;\">\n        <p id=\"3dmolwarning_17296333570725398\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n        </div>\n<script>\n\nvar loadScriptAsync = function(uri){\n  return new Promise((resolve, reject) => {\n    //this is to ignore the existence of requirejs amd\n    var savedexports, savedmodule;\n    if (typeof exports !== 'undefined') savedexports = exports;\n    else exports = {}\n    if (typeof module !== 'undefined') savedmodule = module;\n    else module = {}\n\n    var tag = document.createElement('script');\n    tag.src = uri;\n    tag.async = true;\n    tag.onload = () => {\n        exports = savedexports;\n        module = savedmodule;\n        resolve();\n    };\n  var firstScriptTag = document.getElementsByTagName('script')[0];\n  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n});\n};\n\nif(typeof $3Dmolpromise === 'undefined') {\n$3Dmolpromise = null;\n  $3Dmolpromise = loadScriptAsync('https://cdnjs.cloudflare.com/ajax/libs/3Dmol/2.0.4/3Dmol-min.js');\n}\n\nvar viewer_17296333570725398 = null;\nvar warn = document.getElementById(\"3dmolwarning_17296333570725398\");\nif(warn) {\n    warn.parentNode.removeChild(warn);\n}\n$3Dmolpromise.then(function() {\nviewer_17296333570725398 = $3Dmol.createViewer(document.getElementById(\"3dmolviewer_17296333570725398\"),{backgroundColor:\"white\"});\nviewer_17296333570725398.zoomTo();\n\tviewer_17296333570725398.addModel(\"@<TRIPOS>MOLECULE\\n26\\n62 66 0 0 0\\nSMALL\\nNO_CHARGES\\n\\n@<TRIPOS>ATOM\\n1 None -1.2418 3.5647 -0.8459 C\\n2 None -1.3355 2.3758 -0.1400 C\\n3 1 -0.1195 1.7090 0.1769 C\\n4 None 1.0302 2.3547 0.1072 N\\n5 None 1.1089 3.5894 -0.3841 C\\n6 None -0.0059 4.1715 -1.0042 C\\n7 None -2.5551 1.6296 0.1704 C\\n8 None -2.4644 0.3341 0.0369 N\\n9 None -1.2613 -0.2277 -0.1461 C\\n10 2 -0.2027 0.4146 0.6654 N\\n11 None -1.0145 -1.1391 -0.8864 O\\n12 None -3.7020 2.1898 0.5470 N\\n13 None -3.9167 3.5982 0.7787 C\\n14 None -4.9765 4.1150 -0.1977 C\\n15 None -6.1817 3.3409 0.0247 N\\n16 None -5.9621 1.9373 -0.2736 C\\n17 None -4.8996 1.3714 0.6802 C\\n18 None 0.1120 5.5644 -2.0178 Cl\\n19 None 2.4107 4.2536 -0.2830 C\\n20 None 3.6080 3.5277 -0.4515 C\\n21 None 4.8267 4.2078 -0.4686 C\\n22 None 4.8831 5.5665 -0.2422 C\\n23 None 3.7267 6.2793 0.0353 C\\n24 None 2.5203 5.6131 0.0123 C\\n25 None 3.6160 2.2024 -0.6167 O\\n26 None 1.4125 6.3043 0.3589 F\\n27 None -5.4034 1.3322 2.1205 C\\n28 None -2.1118 4.0168 -1.2961 H\\n29 None -4.3005 3.7222 1.7956 H\\n30 None -2.9837 4.1507 0.6929 H\\n31 None -5.1852 5.1670 0.0041 H\\n32 None -4.5990 4.0205 -1.2324 H\\n33 None -6.9516 3.7042 -0.5263 H\\n34 None -6.8994 1.3979 -0.1307 H\\n35 None -5.6198 1.7788 -1.3116 H\\n36 None -4.6176 0.3651 0.3608 H\\n37 None 5.7223 3.6320 -0.6384 H\\n38 None 5.8348 6.0746 -0.2472 H\\n39 None 3.7485 7.3299 0.2748 H\\n40 None 2.7476 1.8445 -0.3269 H\\n41 None -4.5772 1.1479 2.8024 H\\n42 None -6.1246 0.5272 2.2278 H\\n43 None -5.8928 2.2662 2.3818 H\\n44 3 0.9405 -0.3582 0.9830 C\\n45 4 1.0006 -1.7638 0.8517 C\\n46 None 2.2767 -2.3076 0.7586 C\\n47 None 3.4135 -1.5307 0.9051 C\\n48 None 3.2215 -0.2084 1.2604 C\\n49 None 2.0289 0.3536 1.2336 N\\n50 None -0.1481 -2.6963 1.1847 C\\n51 None 0.1339 -3.2961 2.5705 C\\n52 None -0.3542 -3.8057 0.1552 C\\n53 None 2.3769 -3.3689 0.5882 H\\n54 None 4.4010 -1.9508 0.8006 H\\n55 None 4.0403 0.4446 1.5280 H\\n56 None -1.0754 -2.1245 1.2656 H\\n57 None 0.2976 -2.5079 3.3037 H\\n58 None 1.0170 -3.9304 2.5482 H\\n59 None -0.7142 -3.8968 2.8929 H\\n60 None 0.5307 -4.4310 0.0647 H\\n61 None -0.5813 -3.3705 -0.8126 H\\n62 None -1.1874 -4.4360 0.4597 H\\n@<TRIPOS>BOND\\n1 1 2 2\\n2 2 3 1\\n3 3 4 2\\n4 4 5 1\\n5 5 6 2\\n6 6 1 1\\n7 2 7 1\\n8 7 8 2\\n9 8 9 1\\n10 9 10 1\\n11 10 3 1\\n12 9 11 2\\n13 7 12 1\\n14 12 13 1\\n15 13 14 1\\n16 14 15 1\\n17 15 16 1\\n18 16 17 1\\n19 17 12 1\\n20 6 18 1\\n21 5 19 1\\n22 19 20 2\\n23 20 21 1\\n24 21 22 2\\n25 22 23 1\\n26 23 24 2\\n27 24 19 1\\n28 20 25 1\\n29 24 26 1\\n30 17 27 1\\n31 1 28 1\\n32 13 29 1\\n33 13 30 1\\n34 14 31 1\\n35 14 32 1\\n36 15 33 1\\n37 16 34 1\\n38 16 35 1\\n39 17 36 1\\n40 21 37 1\\n41 22 38 1\\n42 23 39 1\\n43 25 40 1\\n44 27 41 1\\n45 27 42 1\\n46 27 43 1\\n47 44 45 2\\n48 45 46 1\\n49 46 47 2\\n50 47 48 1\\n51 48 49 2\\n52 49 44 1\\n53 50 51 1\\n54 50 52 1\\n55 45 50 1\\n56 10 44 1\\n57 46 53 1\\n58 47 54 1\\n59 48 55 1\\n60 50 56 1\\n61 51 57 1\\n62 51 58 1\\n63 51 59 1\\n64 52 60 1\\n65 52 61 1\\n66 52 62 1\\n\\n\",\"mol2\");\n\tviewer_17296333570725398.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n\tviewer_17296333570725398.setHoverable({},true,\"\\n        function(atom,viewer,event,container) {\\n            if(!atom.label) {\\n                atom.label = viewer.addLabel(atom.elem + '(' + atom.index + ')', {position: atom, backgroundColor: 'silver', fontColor:'black'});\\n            }\\n        }\\n        \",\"\\n        function(atom,viewer) { \\n            if(atom.label) {\\n                viewer.removeLabel(atom.label);\\n                delete atom.label;\\n            }\\n        }\\n        \");\n\tviewer_17296333570725398.zoomTo();\n\tviewer_17296333570725398.setBackgroundColor(\"black\");\nviewer_17296333570725398.render();\n});\n</script>",
      "text/html": [
       "<div id=\"3dmolviewer_17296333570725398\"  style=\"position: relative; width: 100%; height: 500px;\">\n",
       "        <p id=\"3dmolwarning_17296333570725398\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n",
       "        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n",
       "        </div>\n",
       "<script>\n",
       "\n",
       "var loadScriptAsync = function(uri){\n",
       "  return new Promise((resolve, reject) => {\n",
       "    //this is to ignore the existence of requirejs amd\n",
       "    var savedexports, savedmodule;\n",
       "    if (typeof exports !== 'undefined') savedexports = exports;\n",
       "    else exports = {}\n",
       "    if (typeof module !== 'undefined') savedmodule = module;\n",
       "    else module = {}\n",
       "\n",
       "    var tag = document.createElement('script');\n",
       "    tag.src = uri;\n",
       "    tag.async = true;\n",
       "    tag.onload = () => {\n",
       "        exports = savedexports;\n",
       "        module = savedmodule;\n",
       "        resolve();\n",
       "    };\n",
       "  var firstScriptTag = document.getElementsByTagName('script')[0];\n",
       "  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n",
       "});\n",
       "};\n",
       "\n",
       "if(typeof $3Dmolpromise === 'undefined') {\n",
       "$3Dmolpromise = null;\n",
       "  $3Dmolpromise = loadScriptAsync('https://cdnjs.cloudflare.com/ajax/libs/3Dmol/2.0.4/3Dmol-min.js');\n",
       "}\n",
       "\n",
       "var viewer_17296333570725398 = null;\n",
       "var warn = document.getElementById(\"3dmolwarning_17296333570725398\");\n",
       "if(warn) {\n",
       "    warn.parentNode.removeChild(warn);\n",
       "}\n",
       "$3Dmolpromise.then(function() {\n",
       "viewer_17296333570725398 = $3Dmol.createViewer(document.getElementById(\"3dmolviewer_17296333570725398\"),{backgroundColor:\"white\"});\n",
       "viewer_17296333570725398.zoomTo();\n",
       "\tviewer_17296333570725398.addModel(\"@<TRIPOS>MOLECULE\\n26\\n62 66 0 0 0\\nSMALL\\nNO_CHARGES\\n\\n@<TRIPOS>ATOM\\n1 None -1.2418 3.5647 -0.8459 C\\n2 None -1.3355 2.3758 -0.1400 C\\n3 1 -0.1195 1.7090 0.1769 C\\n4 None 1.0302 2.3547 0.1072 N\\n5 None 1.1089 3.5894 -0.3841 C\\n6 None -0.0059 4.1715 -1.0042 C\\n7 None -2.5551 1.6296 0.1704 C\\n8 None -2.4644 0.3341 0.0369 N\\n9 None -1.2613 -0.2277 -0.1461 C\\n10 2 -0.2027 0.4146 0.6654 N\\n11 None -1.0145 -1.1391 -0.8864 O\\n12 None -3.7020 2.1898 0.5470 N\\n13 None -3.9167 3.5982 0.7787 C\\n14 None -4.9765 4.1150 -0.1977 C\\n15 None -6.1817 3.3409 0.0247 N\\n16 None -5.9621 1.9373 -0.2736 C\\n17 None -4.8996 1.3714 0.6802 C\\n18 None 0.1120 5.5644 -2.0178 Cl\\n19 None 2.4107 4.2536 -0.2830 C\\n20 None 3.6080 3.5277 -0.4515 C\\n21 None 4.8267 4.2078 -0.4686 C\\n22 None 4.8831 5.5665 -0.2422 C\\n23 None 3.7267 6.2793 0.0353 C\\n24 None 2.5203 5.6131 0.0123 C\\n25 None 3.6160 2.2024 -0.6167 O\\n26 None 1.4125 6.3043 0.3589 F\\n27 None -5.4034 1.3322 2.1205 C\\n28 None -2.1118 4.0168 -1.2961 H\\n29 None -4.3005 3.7222 1.7956 H\\n30 None -2.9837 4.1507 0.6929 H\\n31 None -5.1852 5.1670 0.0041 H\\n32 None -4.5990 4.0205 -1.2324 H\\n33 None -6.9516 3.7042 -0.5263 H\\n34 None -6.8994 1.3979 -0.1307 H\\n35 None -5.6198 1.7788 -1.3116 H\\n36 None -4.6176 0.3651 0.3608 H\\n37 None 5.7223 3.6320 -0.6384 H\\n38 None 5.8348 6.0746 -0.2472 H\\n39 None 3.7485 7.3299 0.2748 H\\n40 None 2.7476 1.8445 -0.3269 H\\n41 None -4.5772 1.1479 2.8024 H\\n42 None -6.1246 0.5272 2.2278 H\\n43 None -5.8928 2.2662 2.3818 H\\n44 3 0.9405 -0.3582 0.9830 C\\n45 4 1.0006 -1.7638 0.8517 C\\n46 None 2.2767 -2.3076 0.7586 C\\n47 None 3.4135 -1.5307 0.9051 C\\n48 None 3.2215 -0.2084 1.2604 C\\n49 None 2.0289 0.3536 1.2336 N\\n50 None -0.1481 -2.6963 1.1847 C\\n51 None 0.1339 -3.2961 2.5705 C\\n52 None -0.3542 -3.8057 0.1552 C\\n53 None 2.3769 -3.3689 0.5882 H\\n54 None 4.4010 -1.9508 0.8006 H\\n55 None 4.0403 0.4446 1.5280 H\\n56 None -1.0754 -2.1245 1.2656 H\\n57 None 0.2976 -2.5079 3.3037 H\\n58 None 1.0170 -3.9304 2.5482 H\\n59 None -0.7142 -3.8968 2.8929 H\\n60 None 0.5307 -4.4310 0.0647 H\\n61 None -0.5813 -3.3705 -0.8126 H\\n62 None -1.1874 -4.4360 0.4597 H\\n@<TRIPOS>BOND\\n1 1 2 2\\n2 2 3 1\\n3 3 4 2\\n4 4 5 1\\n5 5 6 2\\n6 6 1 1\\n7 2 7 1\\n8 7 8 2\\n9 8 9 1\\n10 9 10 1\\n11 10 3 1\\n12 9 11 2\\n13 7 12 1\\n14 12 13 1\\n15 13 14 1\\n16 14 15 1\\n17 15 16 1\\n18 16 17 1\\n19 17 12 1\\n20 6 18 1\\n21 5 19 1\\n22 19 20 2\\n23 20 21 1\\n24 21 22 2\\n25 22 23 1\\n26 23 24 2\\n27 24 19 1\\n28 20 25 1\\n29 24 26 1\\n30 17 27 1\\n31 1 28 1\\n32 13 29 1\\n33 13 30 1\\n34 14 31 1\\n35 14 32 1\\n36 15 33 1\\n37 16 34 1\\n38 16 35 1\\n39 17 36 1\\n40 21 37 1\\n41 22 38 1\\n42 23 39 1\\n43 25 40 1\\n44 27 41 1\\n45 27 42 1\\n46 27 43 1\\n47 44 45 2\\n48 45 46 1\\n49 46 47 2\\n50 47 48 1\\n51 48 49 2\\n52 49 44 1\\n53 50 51 1\\n54 50 52 1\\n55 45 50 1\\n56 10 44 1\\n57 46 53 1\\n58 47 54 1\\n59 48 55 1\\n60 50 56 1\\n61 51 57 1\\n62 51 58 1\\n63 51 59 1\\n64 52 60 1\\n65 52 61 1\\n66 52 62 1\\n\\n\",\"mol2\");\n",
       "\tviewer_17296333570725398.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n",
       "\tviewer_17296333570725398.setHoverable({},true,\"\\n        function(atom,viewer,event,container) {\\n            if(!atom.label) {\\n                atom.label = viewer.addLabel(atom.elem + '(' + atom.index + ')', {position: atom, backgroundColor: 'silver', fontColor:'black'});\\n            }\\n        }\\n        \",\"\\n        function(atom,viewer) { \\n            if(atom.label) {\\n                viewer.removeLabel(atom.label);\\n                delete atom.label;\\n            }\\n        }\\n        \");\n",
       "\tviewer_17296333570725398.zoomTo();\n",
       "\tviewer_17296333570725398.setBackgroundColor(\"black\");\n",
       "viewer_17296333570725398.render();\n",
       "});\n",
       "</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/3dmoljs_load.v0": "<script>\n            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n                \n                viewer_17296333570725398.render();\n            });\n            </script>",
      "text/html": [
       "<script>\n",
       "            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n",
       "                \n",
       "                viewer_17296333570725398.render();\n",
       "            });\n",
       "            </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/3dmoljs_load.v0": "<script>\n            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n                \tviewer_17296333570725398.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n\n                viewer_17296333570725398.render();\n            });\n            </script>",
      "text/html": [
       "<script>\n",
       "            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n",
       "                \tviewer_17296333570725398.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n",
       "\n",
       "                viewer_17296333570725398.render();\n",
       "            });\n",
       "            </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# This will show both\n",
    "%mlib_view rb_eq_g0.mlib 26_eq1\n",
    "%mlib_view rb_ts_g0.mlib 26"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we need to perform geometry optimizations with ORCA. For transition states we will be using the eigenvector following."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================================================================\n",
      "Optimizing the equilibrium structures\n",
      "Submitting jobs: 0it [00:00, ?it/s]\n",
      "Waiting for jobs: 0it [00:00, ?it/s]\n",
      "Finalizing the calculations: 100%|██████████████| 18/18 [00:00<00:00, 37.60it/s]\n",
      "================================================================================\n",
      "Optimizing the transition structures\n",
      "Submitting jobs: 0it [00:00, ?it/s]\n",
      "Waiting for jobs: 0it [00:00, ?it/s]\n",
      "Finalizing the calculations: 100%|████████████████| 9/9 [00:00<00:00, 12.20it/s]\n"
     ]
    }
   ],
   "source": [
    "!python rb_w1_opt.py"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 3: Extracting preliminary barrier and TS geometry\n",
    "This is the final step in which we will analyze the obtained outputs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Barrier for 23:   3.7,   4.0, freq[6]=-74.12\n",
      "Barrier for 25:  34.9,  35.5, freq[6]=-39.53\n",
      "Barrier for 28:  16.7,  16.5, freq[6]=-33.68\n",
      "Barrier for 27:  17.2,  17.7, freq[6]=-35.69\n",
      "Barrier for 18:  25.9,  25.5, freq[6]=-33.52\n",
      "Barrier for 29:  24.5,  25.1, freq[6]=-30.06\n",
      "Barrier for 24:  47.6,  48.1, freq[6]=-24.92\n",
      "Barrier for 26:  22.1,  21.4, freq[6]=-27.45\n"
     ]
    },
    {
     "data": {
      "application/3dmoljs_load.v0": "<div id=\"3dmolviewer_17296333595230744\"  style=\"position: relative; width: 100%; height: 500px;\">\n        <p id=\"3dmolwarning_17296333595230744\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n        </div>\n<script>\n\nvar loadScriptAsync = function(uri){\n  return new Promise((resolve, reject) => {\n    //this is to ignore the existence of requirejs amd\n    var savedexports, savedmodule;\n    if (typeof exports !== 'undefined') savedexports = exports;\n    else exports = {}\n    if (typeof module !== 'undefined') savedmodule = module;\n    else module = {}\n\n    var tag = document.createElement('script');\n    tag.src = uri;\n    tag.async = true;\n    tag.onload = () => {\n        exports = savedexports;\n        module = savedmodule;\n        resolve();\n    };\n  var firstScriptTag = document.getElementsByTagName('script')[0];\n  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n});\n};\n\nif(typeof $3Dmolpromise === 'undefined') {\n$3Dmolpromise = null;\n  $3Dmolpromise = loadScriptAsync('https://cdnjs.cloudflare.com/ajax/libs/3Dmol/2.0.4/3Dmol-min.js');\n}\n\nvar viewer_17296333595230744 = null;\nvar warn = document.getElementById(\"3dmolwarning_17296333595230744\");\nif(warn) {\n    warn.parentNode.removeChild(warn);\n}\n$3Dmolpromise.then(function() {\nviewer_17296333595230744 = $3Dmol.createViewer(document.getElementById(\"3dmolviewer_17296333595230744\"),{backgroundColor:\"white\"});\nviewer_17296333595230744.zoomTo();\n\tviewer_17296333595230744.addModel(\"@<TRIPOS>MOLECULE\\n26\\n62 66 0 0 0\\nSMALL\\nNO_CHARGES\\n\\n@<TRIPOS>ATOM\\n1 None -1.2872 3.6916 -0.7273 C\\n2 None -1.3479 2.4178 -0.1737 C\\n3 1 -0.1335 1.7292 -0.0092 C\\n4 None 1.0335 2.3209 -0.2280 N\\n5 None 1.1163 3.6028 -0.6137 C\\n6 None -0.0668 4.2868 -0.9639 C\\n7 None -2.5638 1.6430 0.0415 C\\n8 None -2.5185 0.3548 -0.1756 N\\n9 None -1.3266 -0.2572 -0.4161 C\\n10 2 -0.1895 0.3604 0.2622 N\\n11 None -1.1854 -1.2375 -1.1133 O\\n12 None -3.7375 2.2307 0.3668 N\\n13 None -3.8284 3.4739 1.1278 C\\n14 None -4.9769 4.3184 0.6214 C\\n15 None -6.1975 3.5334 0.6918 N\\n16 None -6.0972 2.3487 -0.1475 C\\n17 None -4.9774 1.4363 0.3394 C\\n18 None -0.0557 5.7883 -1.8587 Cl\\n19 None 2.4721 4.1328 -0.7504 C\\n20 None 3.5246 3.2962 -1.2097 C\\n21 None 4.7836 3.8347 -1.4680 C\\n22 None 5.0434 5.1613 -1.1914 C\\n23 None 4.0698 5.9771 -0.6274 C\\n24 None 2.8209 5.4430 -0.4093 C\\n25 None 3.3487 1.9836 -1.4222 O\\n26 None 1.9101 6.2141 0.2272 F\\n27 None -5.2698 0.7682 1.6733 C\\n28 None -2.1908 4.1993 -1.0290 H\\n29 None -4.0040 3.2303 2.1780 H\\n30 None -2.8914 4.0121 1.0752 H\\n31 None -5.0772 5.1992 1.2547 H\\n32 None -4.7441 4.6615 -0.4008 H\\n33 None -6.9918 4.0924 0.4118 H\\n34 None -7.0385 1.8026 -0.1057 H\\n35 None -5.8992 2.5967 -1.2021 H\\n36 None -4.8159 0.6621 -0.4054 H\\n37 None 5.5493 3.1778 -1.8530 H\\n38 None 6.0305 5.5624 -1.3767 H\\n39 None 4.2724 6.9963 -0.3361 H\\n40 None 2.5119 1.7349 -0.9521 H\\n41 None -4.4114 0.1860 1.9985 H\\n42 None -6.1137 0.0886 1.5655 H\\n43 None -5.5265 1.4926 2.4414 H\\n44 3 0.7476 -0.2409 1.1590 C\\n45 4 0.9453 -1.6226 1.3914 C\\n46 None 2.0520 -1.9291 2.1832 C\\n47 None 2.8328 -0.9651 2.7888 C\\n48 None 2.4304 0.3477 2.6307 C\\n49 None 1.4227 0.6833 1.8435 N\\n50 None 0.0919 -2.7919 0.9411 C\\n51 None -0.2535 -3.7254 2.1026 C\\n52 None 0.7622 -3.5510 -0.2012 C\\n53 None 2.2873 -2.9710 2.3459 H\\n54 None 3.6856 -1.2266 3.3992 H\\n55 None 2.9194 1.1615 3.1541 H\\n56 None -0.8499 -2.4216 0.5681 H\\n57 None -0.6742 -3.1752 2.9432 H\\n58 None 0.6063 -4.2855 2.4678 H\\n59 None -0.9929 -4.4548 1.7740 H\\n60 None 1.7148 -3.9766 0.1162 H\\n61 None 0.9435 -2.8946 -1.0475 H\\n62 None 0.1267 -4.3680 -0.5413 H\\n@<TRIPOS>BOND\\n1 1 2 2\\n2 2 3 1\\n3 3 4 2\\n4 4 5 1\\n5 5 6 2\\n6 6 1 1\\n7 2 7 1\\n8 7 8 2\\n9 8 9 1\\n10 9 10 1\\n11 10 3 1\\n12 9 11 2\\n13 7 12 1\\n14 12 13 1\\n15 13 14 1\\n16 14 15 1\\n17 15 16 1\\n18 16 17 1\\n19 17 12 1\\n20 6 18 1\\n21 5 19 1\\n22 19 20 2\\n23 20 21 1\\n24 21 22 2\\n25 22 23 1\\n26 23 24 2\\n27 24 19 1\\n28 20 25 1\\n29 24 26 1\\n30 17 27 1\\n31 1 28 1\\n32 13 29 1\\n33 13 30 1\\n34 14 31 1\\n35 14 32 1\\n36 15 33 1\\n37 16 34 1\\n38 16 35 1\\n39 17 36 1\\n40 21 37 1\\n41 22 38 1\\n42 23 39 1\\n43 25 40 1\\n44 27 41 1\\n45 27 42 1\\n46 27 43 1\\n47 44 45 2\\n48 45 46 1\\n49 46 47 2\\n50 47 48 1\\n51 48 49 2\\n52 49 44 1\\n53 50 51 1\\n54 50 52 1\\n55 45 50 1\\n56 10 44 1\\n57 46 53 1\\n58 47 54 1\\n59 48 55 1\\n60 50 56 1\\n61 51 57 1\\n62 51 58 1\\n63 51 59 1\\n64 52 60 1\\n65 52 61 1\\n66 52 62 1\\n\\n\",\"mol2\");\n\tviewer_17296333595230744.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n\tviewer_17296333595230744.setHoverable({},true,\"\\n        function(atom,viewer,event,container) {\\n            if(!atom.label) {\\n                atom.label = viewer.addLabel(atom.elem + '(' + atom.index + ')', {position: atom, backgroundColor: 'silver', fontColor:'black'});\\n            }\\n        }\\n        \",\"\\n        function(atom,viewer) { \\n            if(atom.label) {\\n                viewer.removeLabel(atom.label);\\n                delete atom.label;\\n            }\\n        }\\n        \");\n\tviewer_17296333595230744.zoomTo();\n\tviewer_17296333595230744.setBackgroundColor(\"black\");\nviewer_17296333595230744.render();\n});\n</script>",
      "text/html": [
       "<div id=\"3dmolviewer_17296333595230744\"  style=\"position: relative; width: 100%; height: 500px;\">\n",
       "        <p id=\"3dmolwarning_17296333595230744\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n",
       "        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n",
       "        </div>\n",
       "<script>\n",
       "\n",
       "var loadScriptAsync = function(uri){\n",
       "  return new Promise((resolve, reject) => {\n",
       "    //this is to ignore the existence of requirejs amd\n",
       "    var savedexports, savedmodule;\n",
       "    if (typeof exports !== 'undefined') savedexports = exports;\n",
       "    else exports = {}\n",
       "    if (typeof module !== 'undefined') savedmodule = module;\n",
       "    else module = {}\n",
       "\n",
       "    var tag = document.createElement('script');\n",
       "    tag.src = uri;\n",
       "    tag.async = true;\n",
       "    tag.onload = () => {\n",
       "        exports = savedexports;\n",
       "        module = savedmodule;\n",
       "        resolve();\n",
       "    };\n",
       "  var firstScriptTag = document.getElementsByTagName('script')[0];\n",
       "  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n",
       "});\n",
       "};\n",
       "\n",
       "if(typeof $3Dmolpromise === 'undefined') {\n",
       "$3Dmolpromise = null;\n",
       "  $3Dmolpromise = loadScriptAsync('https://cdnjs.cloudflare.com/ajax/libs/3Dmol/2.0.4/3Dmol-min.js');\n",
       "}\n",
       "\n",
       "var viewer_17296333595230744 = null;\n",
       "var warn = document.getElementById(\"3dmolwarning_17296333595230744\");\n",
       "if(warn) {\n",
       "    warn.parentNode.removeChild(warn);\n",
       "}\n",
       "$3Dmolpromise.then(function() {\n",
       "viewer_17296333595230744 = $3Dmol.createViewer(document.getElementById(\"3dmolviewer_17296333595230744\"),{backgroundColor:\"white\"});\n",
       "viewer_17296333595230744.zoomTo();\n",
       "\tviewer_17296333595230744.addModel(\"@<TRIPOS>MOLECULE\\n26\\n62 66 0 0 0\\nSMALL\\nNO_CHARGES\\n\\n@<TRIPOS>ATOM\\n1 None -1.2872 3.6916 -0.7273 C\\n2 None -1.3479 2.4178 -0.1737 C\\n3 1 -0.1335 1.7292 -0.0092 C\\n4 None 1.0335 2.3209 -0.2280 N\\n5 None 1.1163 3.6028 -0.6137 C\\n6 None -0.0668 4.2868 -0.9639 C\\n7 None -2.5638 1.6430 0.0415 C\\n8 None -2.5185 0.3548 -0.1756 N\\n9 None -1.3266 -0.2572 -0.4161 C\\n10 2 -0.1895 0.3604 0.2622 N\\n11 None -1.1854 -1.2375 -1.1133 O\\n12 None -3.7375 2.2307 0.3668 N\\n13 None -3.8284 3.4739 1.1278 C\\n14 None -4.9769 4.3184 0.6214 C\\n15 None -6.1975 3.5334 0.6918 N\\n16 None -6.0972 2.3487 -0.1475 C\\n17 None -4.9774 1.4363 0.3394 C\\n18 None -0.0557 5.7883 -1.8587 Cl\\n19 None 2.4721 4.1328 -0.7504 C\\n20 None 3.5246 3.2962 -1.2097 C\\n21 None 4.7836 3.8347 -1.4680 C\\n22 None 5.0434 5.1613 -1.1914 C\\n23 None 4.0698 5.9771 -0.6274 C\\n24 None 2.8209 5.4430 -0.4093 C\\n25 None 3.3487 1.9836 -1.4222 O\\n26 None 1.9101 6.2141 0.2272 F\\n27 None -5.2698 0.7682 1.6733 C\\n28 None -2.1908 4.1993 -1.0290 H\\n29 None -4.0040 3.2303 2.1780 H\\n30 None -2.8914 4.0121 1.0752 H\\n31 None -5.0772 5.1992 1.2547 H\\n32 None -4.7441 4.6615 -0.4008 H\\n33 None -6.9918 4.0924 0.4118 H\\n34 None -7.0385 1.8026 -0.1057 H\\n35 None -5.8992 2.5967 -1.2021 H\\n36 None -4.8159 0.6621 -0.4054 H\\n37 None 5.5493 3.1778 -1.8530 H\\n38 None 6.0305 5.5624 -1.3767 H\\n39 None 4.2724 6.9963 -0.3361 H\\n40 None 2.5119 1.7349 -0.9521 H\\n41 None -4.4114 0.1860 1.9985 H\\n42 None -6.1137 0.0886 1.5655 H\\n43 None -5.5265 1.4926 2.4414 H\\n44 3 0.7476 -0.2409 1.1590 C\\n45 4 0.9453 -1.6226 1.3914 C\\n46 None 2.0520 -1.9291 2.1832 C\\n47 None 2.8328 -0.9651 2.7888 C\\n48 None 2.4304 0.3477 2.6307 C\\n49 None 1.4227 0.6833 1.8435 N\\n50 None 0.0919 -2.7919 0.9411 C\\n51 None -0.2535 -3.7254 2.1026 C\\n52 None 0.7622 -3.5510 -0.2012 C\\n53 None 2.2873 -2.9710 2.3459 H\\n54 None 3.6856 -1.2266 3.3992 H\\n55 None 2.9194 1.1615 3.1541 H\\n56 None -0.8499 -2.4216 0.5681 H\\n57 None -0.6742 -3.1752 2.9432 H\\n58 None 0.6063 -4.2855 2.4678 H\\n59 None -0.9929 -4.4548 1.7740 H\\n60 None 1.7148 -3.9766 0.1162 H\\n61 None 0.9435 -2.8946 -1.0475 H\\n62 None 0.1267 -4.3680 -0.5413 H\\n@<TRIPOS>BOND\\n1 1 2 2\\n2 2 3 1\\n3 3 4 2\\n4 4 5 1\\n5 5 6 2\\n6 6 1 1\\n7 2 7 1\\n8 7 8 2\\n9 8 9 1\\n10 9 10 1\\n11 10 3 1\\n12 9 11 2\\n13 7 12 1\\n14 12 13 1\\n15 13 14 1\\n16 14 15 1\\n17 15 16 1\\n18 16 17 1\\n19 17 12 1\\n20 6 18 1\\n21 5 19 1\\n22 19 20 2\\n23 20 21 1\\n24 21 22 2\\n25 22 23 1\\n26 23 24 2\\n27 24 19 1\\n28 20 25 1\\n29 24 26 1\\n30 17 27 1\\n31 1 28 1\\n32 13 29 1\\n33 13 30 1\\n34 14 31 1\\n35 14 32 1\\n36 15 33 1\\n37 16 34 1\\n38 16 35 1\\n39 17 36 1\\n40 21 37 1\\n41 22 38 1\\n42 23 39 1\\n43 25 40 1\\n44 27 41 1\\n45 27 42 1\\n46 27 43 1\\n47 44 45 2\\n48 45 46 1\\n49 46 47 2\\n50 47 48 1\\n51 48 49 2\\n52 49 44 1\\n53 50 51 1\\n54 50 52 1\\n55 45 50 1\\n56 10 44 1\\n57 46 53 1\\n58 47 54 1\\n59 48 55 1\\n60 50 56 1\\n61 51 57 1\\n62 51 58 1\\n63 51 59 1\\n64 52 60 1\\n65 52 61 1\\n66 52 62 1\\n\\n\",\"mol2\");\n",
       "\tviewer_17296333595230744.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n",
       "\tviewer_17296333595230744.setHoverable({},true,\"\\n        function(atom,viewer,event,container) {\\n            if(!atom.label) {\\n                atom.label = viewer.addLabel(atom.elem + '(' + atom.index + ')', {position: atom, backgroundColor: 'silver', fontColor:'black'});\\n            }\\n        }\\n        \",\"\\n        function(atom,viewer) { \\n            if(atom.label) {\\n                viewer.removeLabel(atom.label);\\n                delete atom.label;\\n            }\\n        }\\n        \");\n",
       "\tviewer_17296333595230744.zoomTo();\n",
       "\tviewer_17296333595230744.setBackgroundColor(\"black\");\n",
       "viewer_17296333595230744.render();\n",
       "});\n",
       "</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/3dmoljs_load.v0": "<script>\n            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n                \n                viewer_17296333595230744.render();\n            });\n            </script>",
      "text/html": [
       "<script>\n",
       "            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n",
       "                \n",
       "                viewer_17296333595230744.render();\n",
       "            });\n",
       "            </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "Molecule(name='26', formula='C26 H26 Cl1 F1 N6 O2')"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# We will analyze the tra\n",
    "import pandas as pd\n",
    "\n",
    "ts_lib = ml.MoleculeLibrary(\"rb_ts_g1.mlib\")\n",
    "eq_lib = ml.MoleculeLibrary(\"rb_eq_g1.mlib\")\n",
    "\n",
    "with ts_lib.reading(), eq_lib.reading():\n",
    "    for key in ts_lib.keys():\n",
    "        if key == \"22\":\n",
    "            continue\n",
    "        ts = ts_lib[key]\n",
    "        freq = ts.attrib[\"ORCA/THERMOCHEMISTRY_Energies\"][\"Vibrational frequencies\"]\n",
    "        \n",
    "        G_ts = ts.attrib[\"ORCA/THERMOCHEMISTRY_Energies\"][\"Gibbs Energy (Hartree)\"]\n",
    "        G_eq1 = eq_lib[key + \"_eq1\"].attrib[\"ORCA/THERMOCHEMISTRY_Energies\"][\"Gibbs Energy (Hartree)\"]\n",
    "        G_eq2 = eq_lib[key + \"_eq2\"].attrib[\"ORCA/THERMOCHEMISTRY_Energies\"][\"Gibbs Energy (Hartree)\"]\n",
    "\n",
    "        dG_act1 = 2625.5*(G_ts - G_eq1)\n",
    "        dG_act2 = 2625.5*(G_ts - G_eq2) \n",
    "        print(f\"Barrier for {key}: {dG_act1/4.184:5.1f}, {dG_act2/4.184:5.1f}, {freq[6]=:5.2f}\")\n",
    "    \n",
    "    ts = ts_lib[\"26\"]\n",
    "\n",
    "ts"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 4. Replace the substituents on the transition state\n",
    "\n",
    "In the previous step we were able to identify a problem: some of the transition states did not converge to what we needed. This can happen, especially considering that XTB geometries can substantially differ from the DFT ones. In order to fix this problem we will use molli's ability to manipulate structures in a streamlined fashion. \n",
    "\n",
    "First, we will remove the substituent from atom \"2\" in the direction of atom \"3\" (and write the corresponding file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "ts.remove_substituent(\"2\", \"3\", ap_label=\"ap1\")\n",
    "with open(\"ts_core.mol2\", \"wt\") as f:\n",
    "    ts.dump_mol2(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create new library\n",
    "from math import radians\n",
    "new_ts_lib = ml.MoleculeLibrary(\"rb_ts_g2.mlib\", readonly=False, overwrite=True)\n",
    "with ts_lib.reading(), new_ts_lib.writing():\n",
    "    for k, m in ts_lib.items():\n",
    "        m.remove_substituent(\"3\", \"2\", ap_label=\"ap2\")\n",
    "        fused = ml.Molecule.join(ts, m, \"ap1\", \"ap2\", optimize_rotation=False,)\n",
    "        fused.rotate_dihedral((\"1\", \"2\", \"3\", \"4\"), radians(180))\n",
    "        fused.name = k\n",
    "        new_ts_lib[k] = fused\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Optimizing the transition structures\n",
      "Submitting jobs: 0it [00:00, ?it/s]\n",
      "Waiting for jobs: 0it [00:00, ?it/s]\n",
      "Finalizing the calculations: 100%|████████████████| 9/9 [00:00<00:00, 16.42it/s]\n"
     ]
    }
   ],
   "source": [
    "!python rb_w2_opt.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/3dmoljs_load.v0": "<div id=\"3dmolviewer_1729633361183081\"  style=\"position: relative; width: 100%; height: 500px;\">\n        <p id=\"3dmolwarning_1729633361183081\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n        </div>\n<script>\n\nvar loadScriptAsync = function(uri){\n  return new Promise((resolve, reject) => {\n    //this is to ignore the existence of requirejs amd\n    var savedexports, savedmodule;\n    if (typeof exports !== 'undefined') savedexports = exports;\n    else exports = {}\n    if (typeof module !== 'undefined') savedmodule = module;\n    else module = {}\n\n    var tag = document.createElement('script');\n    tag.src = uri;\n    tag.async = true;\n    tag.onload = () => {\n        exports = savedexports;\n        module = savedmodule;\n        resolve();\n    };\n  var firstScriptTag = document.getElementsByTagName('script')[0];\n  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n});\n};\n\nif(typeof $3Dmolpromise === 'undefined') {\n$3Dmolpromise = null;\n  $3Dmolpromise = loadScriptAsync('https://cdnjs.cloudflare.com/ajax/libs/3Dmol/2.0.4/3Dmol-min.js');\n}\n\nvar viewer_1729633361183081 = null;\nvar warn = document.getElementById(\"3dmolwarning_1729633361183081\");\nif(warn) {\n    warn.parentNode.removeChild(warn);\n}\n$3Dmolpromise.then(function() {\nviewer_1729633361183081 = $3Dmol.createViewer(document.getElementById(\"3dmolviewer_1729633361183081\"),{backgroundColor:\"white\"});\nviewer_1729633361183081.zoomTo();\n\tviewer_1729633361183081.addModel(\"@<TRIPOS>MOLECULE\\n23\\n66 70 0 0 0\\nSMALL\\nNO_CHARGES\\n\\n@<TRIPOS>ATOM\\n1 None -1.3040 3.1828 1.3463 C\\n2 None -1.5420 2.0766 0.5350 C\\n3 1 -0.3956 1.3745 0.1131 C\\n4 None 0.8180 1.9164 0.1718 N\\n5 None 1.0337 3.0899 0.7872 C\\n6 None -0.0241 3.6682 1.5177 C\\n7 None -2.8278 1.4678 0.2433 C\\n8 None -2.9065 0.2500 -0.2347 N\\n9 None -1.8065 -0.4926 -0.5629 C\\n10 2 -0.5208 0.0858 -0.3199 N\\n11 None -1.8704 -1.5965 -1.0691 O\\n12 None -3.9844 2.1400 0.5138 N\\n13 None -4.1382 3.5636 0.2103 C\\n14 None -4.9689 3.7540 -1.0489 C\\n15 None -6.2459 3.0814 -0.9021 N\\n16 None -6.0408 1.6482 -0.7306 C\\n17 None -5.2568 1.3916 0.5492 C\\n18 None 0.2336 4.8931 2.7382 Cl\\n19 None 2.3952 3.6085 0.7080 C\\n20 None 3.5067 2.7221 0.6949 C\\n21 None 4.8041 3.2260 0.7656 C\\n22 None 5.0249 4.5873 0.7513 C\\n23 None 3.9659 5.4810 0.6419 C\\n24 None 2.6882 4.9740 0.6087 C\\n25 None 3.3627 1.3905 0.6341 O\\n26 None 1.6741 5.8439 0.4053 F\\n27 None -6.0367 1.7366 1.8071 C\\n28 None -2.1132 3.6445 1.8892 H\\n29 None -4.6153 4.0698 1.0491 H\\n30 None -3.1662 4.0126 0.0530 H\\n31 None -5.1343 4.8211 -1.1989 H\\n32 None -4.3838 3.3793 -1.9055 H\\n33 None -6.8248 3.2538 -1.7128 H\\n34 None -7.0098 1.1548 -0.6657 H\\n35 None -5.4851 1.1964 -1.5642 H\\n36 None -4.9844 0.3422 0.5652 H\\n37 None 5.6220 2.5215 0.7931 H\\n38 None 6.0377 4.9650 0.7846 H\\n39 None 4.1194 6.5457 0.5562 H\\n40 None 2.4327 1.2122 0.3465 H\\n41 None -5.4125 1.6163 2.6903 H\\n42 None -6.8864 1.0621 1.9021 H\\n43 None -6.4263 2.7507 1.7841 H\\n44 3 0.6547 -0.6522 -0.7029 C\\n45 4 1.3699 -1.4686 0.1892 C\\n46 None 2.5101 -2.0767 -0.3464 C\\n47 None 2.9160 -1.9049 -1.6592 C\\n48 None 2.1800 -1.1049 -2.5143 C\\n49 None 1.0507 -0.4819 -2.0218 C\\n50 None 0.9727 -1.7437 1.6514 C\\n51 None 1.9790 -2.6742 2.3365 C\\n52 None -0.3936 -2.4374 1.7179 C\\n53 None 0.9313 -0.4592 2.4895 C\\n54 None 3.1145 -2.7097 0.2804 H\\n55 None 3.8109 -2.4027 -2.0078 H\\n56 None 2.4784 -0.9636 -3.5440 H\\n57 None 0.4505 0.1545 -2.6570 H\\n58 None 2.9799 -2.2468 2.3695 H\\n59 None 2.0309 -3.6499 1.8568 H\\n60 None 1.6628 -2.8388 3.3647 H\\n61 None -0.4298 -3.3066 1.0653 H\\n62 None -1.2078 -1.7829 1.4322 H\\n63 None -0.5844 -2.7664 2.7395 H\\n64 None 1.8718 0.0835 2.4335 H\\n65 None 0.7556 -0.7169 3.5335 H\\n66 None 0.1303 0.2089 2.1927 H\\n@<TRIPOS>BOND\\n1 1 2 2\\n2 2 3 1\\n3 3 4 2\\n4 4 5 1\\n5 5 6 2\\n6 6 1 1\\n7 2 7 1\\n8 7 8 2\\n9 8 9 1\\n10 9 10 1\\n11 10 3 1\\n12 9 11 2\\n13 7 12 1\\n14 12 13 1\\n15 13 14 1\\n16 14 15 1\\n17 15 16 1\\n18 16 17 1\\n19 17 12 1\\n20 6 18 1\\n21 5 19 1\\n22 19 20 2\\n23 20 21 1\\n24 21 22 2\\n25 22 23 1\\n26 23 24 2\\n27 24 19 1\\n28 20 25 1\\n29 24 26 1\\n30 17 27 1\\n31 1 28 1\\n32 13 29 1\\n33 13 30 1\\n34 14 31 1\\n35 14 32 1\\n36 15 33 1\\n37 16 34 1\\n38 16 35 1\\n39 17 36 1\\n40 21 37 1\\n41 22 38 1\\n42 23 39 1\\n43 25 40 1\\n44 27 41 1\\n45 27 42 1\\n46 27 43 1\\n47 44 45 2\\n48 45 46 1\\n49 46 47 2\\n50 47 48 1\\n51 48 49 2\\n52 49 44 1\\n53 50 51 1\\n54 50 52 1\\n55 50 53 1\\n56 45 50 1\\n57 10 44 1\\n58 46 54 1\\n59 47 55 1\\n60 48 56 1\\n61 49 57 1\\n62 51 58 1\\n63 51 59 1\\n64 51 60 1\\n65 52 61 1\\n66 52 62 1\\n67 52 63 1\\n68 53 64 1\\n69 53 65 1\\n70 53 66 1\\n\\n\",\"mol2\");\n\tviewer_1729633361183081.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n\tviewer_1729633361183081.setHoverable({},true,\"\\n        function(atom,viewer,event,container) {\\n            if(!atom.label) {\\n                atom.label = viewer.addLabel(atom.elem + '(' + atom.index + ')', {position: atom, backgroundColor: 'silver', fontColor:'black'});\\n            }\\n        }\\n        \",\"\\n        function(atom,viewer) { \\n            if(atom.label) {\\n                viewer.removeLabel(atom.label);\\n                delete atom.label;\\n            }\\n        }\\n        \");\n\tviewer_1729633361183081.zoomTo();\n\tviewer_1729633361183081.setBackgroundColor(\"black\");\nviewer_1729633361183081.render();\n});\n</script>",
      "text/html": [
       "<div id=\"3dmolviewer_1729633361183081\"  style=\"position: relative; width: 100%; height: 500px;\">\n",
       "        <p id=\"3dmolwarning_1729633361183081\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n",
       "        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n",
       "        </div>\n",
       "<script>\n",
       "\n",
       "var loadScriptAsync = function(uri){\n",
       "  return new Promise((resolve, reject) => {\n",
       "    //this is to ignore the existence of requirejs amd\n",
       "    var savedexports, savedmodule;\n",
       "    if (typeof exports !== 'undefined') savedexports = exports;\n",
       "    else exports = {}\n",
       "    if (typeof module !== 'undefined') savedmodule = module;\n",
       "    else module = {}\n",
       "\n",
       "    var tag = document.createElement('script');\n",
       "    tag.src = uri;\n",
       "    tag.async = true;\n",
       "    tag.onload = () => {\n",
       "        exports = savedexports;\n",
       "        module = savedmodule;\n",
       "        resolve();\n",
       "    };\n",
       "  var firstScriptTag = document.getElementsByTagName('script')[0];\n",
       "  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n",
       "});\n",
       "};\n",
       "\n",
       "if(typeof $3Dmolpromise === 'undefined') {\n",
       "$3Dmolpromise = null;\n",
       "  $3Dmolpromise = loadScriptAsync('https://cdnjs.cloudflare.com/ajax/libs/3Dmol/2.0.4/3Dmol-min.js');\n",
       "}\n",
       "\n",
       "var viewer_1729633361183081 = null;\n",
       "var warn = document.getElementById(\"3dmolwarning_1729633361183081\");\n",
       "if(warn) {\n",
       "    warn.parentNode.removeChild(warn);\n",
       "}\n",
       "$3Dmolpromise.then(function() {\n",
       "viewer_1729633361183081 = $3Dmol.createViewer(document.getElementById(\"3dmolviewer_1729633361183081\"),{backgroundColor:\"white\"});\n",
       "viewer_1729633361183081.zoomTo();\n",
       "\tviewer_1729633361183081.addModel(\"@<TRIPOS>MOLECULE\\n23\\n66 70 0 0 0\\nSMALL\\nNO_CHARGES\\n\\n@<TRIPOS>ATOM\\n1 None -1.3040 3.1828 1.3463 C\\n2 None -1.5420 2.0766 0.5350 C\\n3 1 -0.3956 1.3745 0.1131 C\\n4 None 0.8180 1.9164 0.1718 N\\n5 None 1.0337 3.0899 0.7872 C\\n6 None -0.0241 3.6682 1.5177 C\\n7 None -2.8278 1.4678 0.2433 C\\n8 None -2.9065 0.2500 -0.2347 N\\n9 None -1.8065 -0.4926 -0.5629 C\\n10 2 -0.5208 0.0858 -0.3199 N\\n11 None -1.8704 -1.5965 -1.0691 O\\n12 None -3.9844 2.1400 0.5138 N\\n13 None -4.1382 3.5636 0.2103 C\\n14 None -4.9689 3.7540 -1.0489 C\\n15 None -6.2459 3.0814 -0.9021 N\\n16 None -6.0408 1.6482 -0.7306 C\\n17 None -5.2568 1.3916 0.5492 C\\n18 None 0.2336 4.8931 2.7382 Cl\\n19 None 2.3952 3.6085 0.7080 C\\n20 None 3.5067 2.7221 0.6949 C\\n21 None 4.8041 3.2260 0.7656 C\\n22 None 5.0249 4.5873 0.7513 C\\n23 None 3.9659 5.4810 0.6419 C\\n24 None 2.6882 4.9740 0.6087 C\\n25 None 3.3627 1.3905 0.6341 O\\n26 None 1.6741 5.8439 0.4053 F\\n27 None -6.0367 1.7366 1.8071 C\\n28 None -2.1132 3.6445 1.8892 H\\n29 None -4.6153 4.0698 1.0491 H\\n30 None -3.1662 4.0126 0.0530 H\\n31 None -5.1343 4.8211 -1.1989 H\\n32 None -4.3838 3.3793 -1.9055 H\\n33 None -6.8248 3.2538 -1.7128 H\\n34 None -7.0098 1.1548 -0.6657 H\\n35 None -5.4851 1.1964 -1.5642 H\\n36 None -4.9844 0.3422 0.5652 H\\n37 None 5.6220 2.5215 0.7931 H\\n38 None 6.0377 4.9650 0.7846 H\\n39 None 4.1194 6.5457 0.5562 H\\n40 None 2.4327 1.2122 0.3465 H\\n41 None -5.4125 1.6163 2.6903 H\\n42 None -6.8864 1.0621 1.9021 H\\n43 None -6.4263 2.7507 1.7841 H\\n44 3 0.6547 -0.6522 -0.7029 C\\n45 4 1.3699 -1.4686 0.1892 C\\n46 None 2.5101 -2.0767 -0.3464 C\\n47 None 2.9160 -1.9049 -1.6592 C\\n48 None 2.1800 -1.1049 -2.5143 C\\n49 None 1.0507 -0.4819 -2.0218 C\\n50 None 0.9727 -1.7437 1.6514 C\\n51 None 1.9790 -2.6742 2.3365 C\\n52 None -0.3936 -2.4374 1.7179 C\\n53 None 0.9313 -0.4592 2.4895 C\\n54 None 3.1145 -2.7097 0.2804 H\\n55 None 3.8109 -2.4027 -2.0078 H\\n56 None 2.4784 -0.9636 -3.5440 H\\n57 None 0.4505 0.1545 -2.6570 H\\n58 None 2.9799 -2.2468 2.3695 H\\n59 None 2.0309 -3.6499 1.8568 H\\n60 None 1.6628 -2.8388 3.3647 H\\n61 None -0.4298 -3.3066 1.0653 H\\n62 None -1.2078 -1.7829 1.4322 H\\n63 None -0.5844 -2.7664 2.7395 H\\n64 None 1.8718 0.0835 2.4335 H\\n65 None 0.7556 -0.7169 3.5335 H\\n66 None 0.1303 0.2089 2.1927 H\\n@<TRIPOS>BOND\\n1 1 2 2\\n2 2 3 1\\n3 3 4 2\\n4 4 5 1\\n5 5 6 2\\n6 6 1 1\\n7 2 7 1\\n8 7 8 2\\n9 8 9 1\\n10 9 10 1\\n11 10 3 1\\n12 9 11 2\\n13 7 12 1\\n14 12 13 1\\n15 13 14 1\\n16 14 15 1\\n17 15 16 1\\n18 16 17 1\\n19 17 12 1\\n20 6 18 1\\n21 5 19 1\\n22 19 20 2\\n23 20 21 1\\n24 21 22 2\\n25 22 23 1\\n26 23 24 2\\n27 24 19 1\\n28 20 25 1\\n29 24 26 1\\n30 17 27 1\\n31 1 28 1\\n32 13 29 1\\n33 13 30 1\\n34 14 31 1\\n35 14 32 1\\n36 15 33 1\\n37 16 34 1\\n38 16 35 1\\n39 17 36 1\\n40 21 37 1\\n41 22 38 1\\n42 23 39 1\\n43 25 40 1\\n44 27 41 1\\n45 27 42 1\\n46 27 43 1\\n47 44 45 2\\n48 45 46 1\\n49 46 47 2\\n50 47 48 1\\n51 48 49 2\\n52 49 44 1\\n53 50 51 1\\n54 50 52 1\\n55 50 53 1\\n56 45 50 1\\n57 10 44 1\\n58 46 54 1\\n59 47 55 1\\n60 48 56 1\\n61 49 57 1\\n62 51 58 1\\n63 51 59 1\\n64 51 60 1\\n65 52 61 1\\n66 52 62 1\\n67 52 63 1\\n68 53 64 1\\n69 53 65 1\\n70 53 66 1\\n\\n\",\"mol2\");\n",
       "\tviewer_1729633361183081.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n",
       "\tviewer_1729633361183081.setHoverable({},true,\"\\n        function(atom,viewer,event,container) {\\n            if(!atom.label) {\\n                atom.label = viewer.addLabel(atom.elem + '(' + atom.index + ')', {position: atom, backgroundColor: 'silver', fontColor:'black'});\\n            }\\n        }\\n        \",\"\\n        function(atom,viewer) { \\n            if(atom.label) {\\n                viewer.removeLabel(atom.label);\\n                delete atom.label;\\n            }\\n        }\\n        \");\n",
       "\tviewer_1729633361183081.zoomTo();\n",
       "\tviewer_1729633361183081.setBackgroundColor(\"black\");\n",
       "viewer_1729633361183081.render();\n",
       "});\n",
       "</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/3dmoljs_load.v0": "<script>\n            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n                \n                viewer_1729633361183081.render();\n            });\n            </script>",
      "text/html": [
       "<script>\n",
       "            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n",
       "                \n",
       "                viewer_1729633361183081.render();\n",
       "            });\n",
       "            </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/3dmoljs_load.v0": "<script>\n            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n                \tviewer_1729633361183081.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n\n                viewer_1729633361183081.render();\n            });\n            </script>",
      "text/html": [
       "<script>\n",
       "            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n",
       "                \tviewer_1729633361183081.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n",
       "\n",
       "                viewer_1729633361183081.render();\n",
       "            });\n",
       "            </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# In this line one can make sure that all of the transition states look solid now!\n",
    "%mlib_view rb_eq_g1.mlib 23_eq1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 5. Compile the data in a presentable form."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>barrier (R-&gt;TS)</th>\n",
       "      <th>barrier (S-&gt;TS)</th>\n",
       "      <th>TS low freq</th>\n",
       "      <th>TS N imag freq</th>\n",
       "      <th>EQ1 N imag freq</th>\n",
       "      <th>EQ2 N imag freq</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>108.3</td>\n",
       "      <td>106.7</td>\n",
       "      <td>-32.2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>103.2</td>\n",
       "      <td>102.6</td>\n",
       "      <td>-36.5</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>132.0</td>\n",
       "      <td>133.3</td>\n",
       "      <td>-48.3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>150.0</td>\n",
       "      <td>151.9</td>\n",
       "      <td>-30.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>146.1</td>\n",
       "      <td>148.4</td>\n",
       "      <td>-35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>92.6</td>\n",
       "      <td>89.4</td>\n",
       "      <td>-27.8</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>73.7</td>\n",
       "      <td>76.0</td>\n",
       "      <td>-38.6</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>69.9</td>\n",
       "      <td>69.2</td>\n",
       "      <td>-35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>101.3</td>\n",
       "      <td>103.8</td>\n",
       "      <td>-25.5</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    barrier (R->TS)  barrier (S->TS)  TS low freq  TS N imag freq  \\\n",
       "18            108.3            106.7        -32.2               1   \n",
       "22            103.2            102.6        -36.5               1   \n",
       "23            132.0            133.3        -48.3               1   \n",
       "24            150.0            151.9        -30.0               1   \n",
       "25            146.1            148.4        -35.0               1   \n",
       "26             92.6             89.4        -27.8               1   \n",
       "27             73.7             76.0        -38.6               1   \n",
       "28             69.9             69.2        -35.0               1   \n",
       "29            101.3            103.8        -25.5               1   \n",
       "\n",
       "    EQ1 N imag freq  EQ2 N imag freq  \n",
       "18                0                0  \n",
       "22                0                0  \n",
       "23                1                0  \n",
       "24                0                0  \n",
       "25                0                0  \n",
       "26                0                0  \n",
       "27                0                0  \n",
       "28                0                0  \n",
       "29                0                0  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ts_lib = ml.MoleculeLibrary(\"rb_ts_g3.mlib\")\n",
    "eq_lib = ml.MoleculeLibrary(\"rb_eq_g1.mlib\")\n",
    "\n",
    "with ts_lib.reading(), eq_lib.reading():\n",
    "    data = {}\n",
    "    for key in sorted(ts_lib.keys()):\n",
    "        ts = ts_lib[key]\n",
    "        ts_freq = ts.attrib[\"ORCA/THERMOCHEMISTRY_Energies\"][\"Vibrational frequencies\"]\n",
    "        G_ts = ts.attrib[\"ORCA/THERMOCHEMISTRY_Energies\"][\"Gibbs Energy (Hartree)\"]\n",
    "\n",
    "        eq1 = eq_lib[key + \"_eq1\"]\n",
    "        G_eq1 = eq1.attrib[\"ORCA/THERMOCHEMISTRY_Energies\"][\n",
    "            \"Gibbs Energy (Hartree)\"\n",
    "        ]\n",
    "        eq1_freq = eq1.attrib[\"ORCA/THERMOCHEMISTRY_Energies\"][\"Vibrational frequencies\"]\n",
    "\n",
    "        eq2 = eq_lib[key + \"_eq2\"]\n",
    "        G_eq2 = eq2.attrib[\"ORCA/THERMOCHEMISTRY_Energies\"][\n",
    "            \"Gibbs Energy (Hartree)\"\n",
    "        ]\n",
    "        eq2_freq = eq2.attrib[\"ORCA/THERMOCHEMISTRY_Energies\"][\"Vibrational frequencies\"]\n",
    "\n",
    "        dG_act1 = 2625.5 * (G_ts - G_eq1) # This is the (R) -> TS barrier\n",
    "        dG_act2 = 2625.5 * (G_ts - G_eq2) # This is the (S) -> TS barrier\n",
    "\n",
    "        nim_eq1 =  np.count_nonzero(eq1_freq < 0)\n",
    "        nim_eq2 =  np.count_nonzero(eq2_freq < 0)\n",
    "        nim_ts =  np.count_nonzero(ts_freq < 0)\n",
    "\n",
    "        data[key] = {\n",
    "            # \"barrier (expt)\": \n",
    "            \"barrier (R->TS)\": dG_act1, \n",
    "            \"barrier (S->TS)\": dG_act2,\n",
    "            \"TS low freq\": ts_freq[6],\n",
    "            \"TS N imag freq\": nim_ts,\n",
    "            \"EQ1 N imag freq\": nim_eq1,\n",
    "            \"EQ2 N imag freq\": nim_eq2 \n",
    "        }\n",
    "        # f\"{key}: Barrier={dG_act1:5.1f} ({dG_act2:5.1f}) kJ/mol, TS low freq: {ts_freq[6]:5.2f}, TS #im freq: {nim_ts}, EQ1 #im freq: {nim_eq1}, EQ2 #im freq: {nim_eq2}\"\n",
    "\n",
    "    ts = ts_lib[\"26\"]\n",
    "\n",
    "pd.DataFrame.from_dict(data=data, orient=\"index\").round(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 6. Resolving the imaginary frequency problem\n",
    "\n",
    "As can be seen from the table above, the project is nearly complete now. The only remaining problem is that for compound **23** we have accidentally converged to the transition state (as indicated by a single imaginary frequency). Upon closer inspection one can notice that this is the tert-butyl rotation. Here we have a couple of options for dealing with this, but we are going to use the similar approach as before: we will create a new collection and we will repeat the calculation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/3dmoljs_load.v0": "<div id=\"3dmolviewer_1729633361288349\"  style=\"position: relative; width: 100%; height: 500px;\">\n        <p id=\"3dmolwarning_1729633361288349\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n        </div>\n<script>\n\nvar loadScriptAsync = function(uri){\n  return new Promise((resolve, reject) => {\n    //this is to ignore the existence of requirejs amd\n    var savedexports, savedmodule;\n    if (typeof exports !== 'undefined') savedexports = exports;\n    else exports = {}\n    if (typeof module !== 'undefined') savedmodule = module;\n    else module = {}\n\n    var tag = document.createElement('script');\n    tag.src = uri;\n    tag.async = true;\n    tag.onload = () => {\n        exports = savedexports;\n        module = savedmodule;\n        resolve();\n    };\n  var firstScriptTag = document.getElementsByTagName('script')[0];\n  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n});\n};\n\nif(typeof $3Dmolpromise === 'undefined') {\n$3Dmolpromise = null;\n  $3Dmolpromise = loadScriptAsync('https://cdnjs.cloudflare.com/ajax/libs/3Dmol/2.0.4/3Dmol-min.js');\n}\n\nvar viewer_1729633361288349 = null;\nvar warn = document.getElementById(\"3dmolwarning_1729633361288349\");\nif(warn) {\n    warn.parentNode.removeChild(warn);\n}\n$3Dmolpromise.then(function() {\nviewer_1729633361288349 = $3Dmol.createViewer(document.getElementById(\"3dmolviewer_1729633361288349\"),{backgroundColor:\"white\"});\nviewer_1729633361288349.zoomTo();\n\tviewer_1729633361288349.addModel(\"@<TRIPOS>MOLECULE\\n23\\n66 70 0 0 0\\nSMALL\\nNO_CHARGES\\n\\n@<TRIPOS>ATOM\\n1 None 3.5345 -6.4694 0.8443 C\\n2 None 4.0402 -5.1820 0.6855 C\\n3 1 3.1908 -4.2727 0.0247 C\\n4 None 2.1581 -4.6841 -0.7062 N\\n5 None 1.7738 -5.9704 -0.7167 C\\n6 None 2.3840 -6.8599 0.1908 C\\n7 None 5.2438 -4.6360 1.2873 C\\n8 None 5.4381 -3.3417 1.3562 N\\n9 None 4.5793 -2.4305 0.8071 C\\n10 2 3.3970 -2.9316 0.1765 N\\n11 None 4.7847 -1.2319 0.8073 O\\n12 None 6.1737 -5.4670 1.8417 N\\n13 None 6.5826 -6.7117 1.1889 C\\n14 None 7.9372 -6.5429 0.5193 C\\n15 None 8.9124 -6.0848 1.4907 N\\n16 None 8.5229 -4.7816 2.0156 C\\n17 None 7.1928 -4.8998 2.7472 C\\n18 None 1.6711 -8.3951 0.6282 Cl\\n19 None 0.6783 -6.2993 -1.6228 C\\n20 None -0.3577 -5.3591 -1.8755 C\\n21 None -1.4723 -5.7310 -2.6248 C\\n22 None -1.5355 -6.9796 -3.2073 C\\n23 None -0.4842 -7.8801 -3.0811 C\\n24 None 0.5946 -7.5161 -2.3103 C\\n25 None -0.3215 -4.1057 -1.4010 O\\n26 None 1.6509 -8.3583 -2.2735 F\\n27 None 7.2829 -5.7228 4.0215 C\\n28 None 4.0109 -7.1626 1.5192 H\\n29 None 6.6299 -7.5149 1.9238 H\\n30 None 5.8570 -6.9861 0.4343 H\\n31 None 8.2491 -7.5070 0.1167 H\\n32 None 7.8167 -5.8465 -0.3274 H\\n33 None 9.8272 -6.0270 1.0642 H\\n34 None 9.2873 -4.4340 2.7096 H\\n35 None 8.4098 -4.0235 1.2280 H\\n36 None 6.8554 -3.8968 2.9837 H\\n37 None -2.2576 -5.0028 -2.7632 H\\n38 None -2.3963 -7.2479 -3.8045 H\\n39 None -0.4805 -8.8332 -3.5872 H\\n40 None 0.6099 -3.9301 -1.1163 H\\n41 None 6.2978 -5.8496 4.4664 H\\n42 None 7.9128 -5.2045 4.7430 H\\n43 None 7.7221 -6.7014 3.8487 H\\n44 3 2.5001 -1.9991 -0.4551 C\\n45 4 1.3699 -1.4686 0.1892 C\\n46 None 0.5899 -0.6093 -0.5919 C\\n47 None 0.8971 -0.2872 -1.9032 C\\n48 None 2.0257 -0.8169 -2.5020 C\\n49 None 2.8186 -1.6744 -1.7659 C\\n50 None 0.9727 -1.7437 1.6514 C\\n51 None 1.9790 -2.6742 2.3365 C\\n52 None -0.3936 -2.4374 1.7179 C\\n53 None 0.9313 -0.4592 2.4895 C\\n54 None -0.2979 -0.1712 -0.1689 H\\n55 None 0.2479 0.3822 -2.4517 H\\n56 None 2.2845 -0.5722 -3.5230 H\\n57 None 3.7070 -2.1124 -2.1990 H\\n58 None 2.9799 -2.2468 2.3695 H\\n59 None 2.0309 -3.6499 1.8568 H\\n60 None 1.6628 -2.8388 3.3647 H\\n61 None -0.4298 -3.3066 1.0653 H\\n62 None -1.2078 -1.7829 1.4322 H\\n63 None -0.5844 -2.7664 2.7395 H\\n64 None 1.8718 0.0835 2.4335 H\\n65 None 0.7556 -0.7169 3.5335 H\\n66 None 0.1303 0.2089 2.1927 H\\n@<TRIPOS>BOND\\n1 1 2 2\\n2 2 3 1\\n3 3 4 2\\n4 4 5 1\\n5 5 6 2\\n6 6 1 1\\n7 2 7 1\\n8 7 8 2\\n9 8 9 1\\n10 9 10 1\\n11 10 3 1\\n12 9 11 2\\n13 7 12 1\\n14 12 13 1\\n15 13 14 1\\n16 14 15 1\\n17 15 16 1\\n18 16 17 1\\n19 17 12 1\\n20 6 18 1\\n21 5 19 1\\n22 19 20 2\\n23 20 21 1\\n24 21 22 2\\n25 22 23 1\\n26 23 24 2\\n27 24 19 1\\n28 20 25 1\\n29 24 26 1\\n30 17 27 1\\n31 1 28 1\\n32 13 29 1\\n33 13 30 1\\n34 14 31 1\\n35 14 32 1\\n36 15 33 1\\n37 16 34 1\\n38 16 35 1\\n39 17 36 1\\n40 21 37 1\\n41 22 38 1\\n42 23 39 1\\n43 25 40 1\\n44 27 41 1\\n45 27 42 1\\n46 27 43 1\\n47 44 45 2\\n48 45 46 1\\n49 46 47 2\\n50 47 48 1\\n51 48 49 2\\n52 49 44 1\\n53 50 51 1\\n54 50 52 1\\n55 50 53 1\\n56 45 50 1\\n57 10 44 1\\n58 46 54 1\\n59 47 55 1\\n60 48 56 1\\n61 49 57 1\\n62 51 58 1\\n63 51 59 1\\n64 51 60 1\\n65 52 61 1\\n66 52 62 1\\n67 52 63 1\\n68 53 64 1\\n69 53 65 1\\n70 53 66 1\\n\\n\",\"mol2\");\n\tviewer_1729633361288349.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n\tviewer_1729633361288349.setHoverable({},true,\"\\n        function(atom,viewer,event,container) {\\n            if(!atom.label) {\\n                atom.label = viewer.addLabel(atom.elem + '(' + atom.index + ')', {position: atom, backgroundColor: 'silver', fontColor:'black'});\\n            }\\n        }\\n        \",\"\\n        function(atom,viewer) { \\n            if(atom.label) {\\n                viewer.removeLabel(atom.label);\\n                delete atom.label;\\n            }\\n        }\\n        \");\n\tviewer_1729633361288349.zoomTo();\n\tviewer_1729633361288349.setBackgroundColor(\"black\");\nviewer_1729633361288349.render();\n});\n</script>",
      "text/html": [
       "<div id=\"3dmolviewer_1729633361288349\"  style=\"position: relative; width: 100%; height: 500px;\">\n",
       "        <p id=\"3dmolwarning_1729633361288349\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n",
       "        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n",
       "        </div>\n",
       "<script>\n",
       "\n",
       "var loadScriptAsync = function(uri){\n",
       "  return new Promise((resolve, reject) => {\n",
       "    //this is to ignore the existence of requirejs amd\n",
       "    var savedexports, savedmodule;\n",
       "    if (typeof exports !== 'undefined') savedexports = exports;\n",
       "    else exports = {}\n",
       "    if (typeof module !== 'undefined') savedmodule = module;\n",
       "    else module = {}\n",
       "\n",
       "    var tag = document.createElement('script');\n",
       "    tag.src = uri;\n",
       "    tag.async = true;\n",
       "    tag.onload = () => {\n",
       "        exports = savedexports;\n",
       "        module = savedmodule;\n",
       "        resolve();\n",
       "    };\n",
       "  var firstScriptTag = document.getElementsByTagName('script')[0];\n",
       "  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n",
       "});\n",
       "};\n",
       "\n",
       "if(typeof $3Dmolpromise === 'undefined') {\n",
       "$3Dmolpromise = null;\n",
       "  $3Dmolpromise = loadScriptAsync('https://cdnjs.cloudflare.com/ajax/libs/3Dmol/2.0.4/3Dmol-min.js');\n",
       "}\n",
       "\n",
       "var viewer_1729633361288349 = null;\n",
       "var warn = document.getElementById(\"3dmolwarning_1729633361288349\");\n",
       "if(warn) {\n",
       "    warn.parentNode.removeChild(warn);\n",
       "}\n",
       "$3Dmolpromise.then(function() {\n",
       "viewer_1729633361288349 = $3Dmol.createViewer(document.getElementById(\"3dmolviewer_1729633361288349\"),{backgroundColor:\"white\"});\n",
       "viewer_1729633361288349.zoomTo();\n",
       "\tviewer_1729633361288349.addModel(\"@<TRIPOS>MOLECULE\\n23\\n66 70 0 0 0\\nSMALL\\nNO_CHARGES\\n\\n@<TRIPOS>ATOM\\n1 None 3.5345 -6.4694 0.8443 C\\n2 None 4.0402 -5.1820 0.6855 C\\n3 1 3.1908 -4.2727 0.0247 C\\n4 None 2.1581 -4.6841 -0.7062 N\\n5 None 1.7738 -5.9704 -0.7167 C\\n6 None 2.3840 -6.8599 0.1908 C\\n7 None 5.2438 -4.6360 1.2873 C\\n8 None 5.4381 -3.3417 1.3562 N\\n9 None 4.5793 -2.4305 0.8071 C\\n10 2 3.3970 -2.9316 0.1765 N\\n11 None 4.7847 -1.2319 0.8073 O\\n12 None 6.1737 -5.4670 1.8417 N\\n13 None 6.5826 -6.7117 1.1889 C\\n14 None 7.9372 -6.5429 0.5193 C\\n15 None 8.9124 -6.0848 1.4907 N\\n16 None 8.5229 -4.7816 2.0156 C\\n17 None 7.1928 -4.8998 2.7472 C\\n18 None 1.6711 -8.3951 0.6282 Cl\\n19 None 0.6783 -6.2993 -1.6228 C\\n20 None -0.3577 -5.3591 -1.8755 C\\n21 None -1.4723 -5.7310 -2.6248 C\\n22 None -1.5355 -6.9796 -3.2073 C\\n23 None -0.4842 -7.8801 -3.0811 C\\n24 None 0.5946 -7.5161 -2.3103 C\\n25 None -0.3215 -4.1057 -1.4010 O\\n26 None 1.6509 -8.3583 -2.2735 F\\n27 None 7.2829 -5.7228 4.0215 C\\n28 None 4.0109 -7.1626 1.5192 H\\n29 None 6.6299 -7.5149 1.9238 H\\n30 None 5.8570 -6.9861 0.4343 H\\n31 None 8.2491 -7.5070 0.1167 H\\n32 None 7.8167 -5.8465 -0.3274 H\\n33 None 9.8272 -6.0270 1.0642 H\\n34 None 9.2873 -4.4340 2.7096 H\\n35 None 8.4098 -4.0235 1.2280 H\\n36 None 6.8554 -3.8968 2.9837 H\\n37 None -2.2576 -5.0028 -2.7632 H\\n38 None -2.3963 -7.2479 -3.8045 H\\n39 None -0.4805 -8.8332 -3.5872 H\\n40 None 0.6099 -3.9301 -1.1163 H\\n41 None 6.2978 -5.8496 4.4664 H\\n42 None 7.9128 -5.2045 4.7430 H\\n43 None 7.7221 -6.7014 3.8487 H\\n44 3 2.5001 -1.9991 -0.4551 C\\n45 4 1.3699 -1.4686 0.1892 C\\n46 None 0.5899 -0.6093 -0.5919 C\\n47 None 0.8971 -0.2872 -1.9032 C\\n48 None 2.0257 -0.8169 -2.5020 C\\n49 None 2.8186 -1.6744 -1.7659 C\\n50 None 0.9727 -1.7437 1.6514 C\\n51 None 1.9790 -2.6742 2.3365 C\\n52 None -0.3936 -2.4374 1.7179 C\\n53 None 0.9313 -0.4592 2.4895 C\\n54 None -0.2979 -0.1712 -0.1689 H\\n55 None 0.2479 0.3822 -2.4517 H\\n56 None 2.2845 -0.5722 -3.5230 H\\n57 None 3.7070 -2.1124 -2.1990 H\\n58 None 2.9799 -2.2468 2.3695 H\\n59 None 2.0309 -3.6499 1.8568 H\\n60 None 1.6628 -2.8388 3.3647 H\\n61 None -0.4298 -3.3066 1.0653 H\\n62 None -1.2078 -1.7829 1.4322 H\\n63 None -0.5844 -2.7664 2.7395 H\\n64 None 1.8718 0.0835 2.4335 H\\n65 None 0.7556 -0.7169 3.5335 H\\n66 None 0.1303 0.2089 2.1927 H\\n@<TRIPOS>BOND\\n1 1 2 2\\n2 2 3 1\\n3 3 4 2\\n4 4 5 1\\n5 5 6 2\\n6 6 1 1\\n7 2 7 1\\n8 7 8 2\\n9 8 9 1\\n10 9 10 1\\n11 10 3 1\\n12 9 11 2\\n13 7 12 1\\n14 12 13 1\\n15 13 14 1\\n16 14 15 1\\n17 15 16 1\\n18 16 17 1\\n19 17 12 1\\n20 6 18 1\\n21 5 19 1\\n22 19 20 2\\n23 20 21 1\\n24 21 22 2\\n25 22 23 1\\n26 23 24 2\\n27 24 19 1\\n28 20 25 1\\n29 24 26 1\\n30 17 27 1\\n31 1 28 1\\n32 13 29 1\\n33 13 30 1\\n34 14 31 1\\n35 14 32 1\\n36 15 33 1\\n37 16 34 1\\n38 16 35 1\\n39 17 36 1\\n40 21 37 1\\n41 22 38 1\\n42 23 39 1\\n43 25 40 1\\n44 27 41 1\\n45 27 42 1\\n46 27 43 1\\n47 44 45 2\\n48 45 46 1\\n49 46 47 2\\n50 47 48 1\\n51 48 49 2\\n52 49 44 1\\n53 50 51 1\\n54 50 52 1\\n55 50 53 1\\n56 45 50 1\\n57 10 44 1\\n58 46 54 1\\n59 47 55 1\\n60 48 56 1\\n61 49 57 1\\n62 51 58 1\\n63 51 59 1\\n64 51 60 1\\n65 52 61 1\\n66 52 62 1\\n67 52 63 1\\n68 53 64 1\\n69 53 65 1\\n70 53 66 1\\n\\n\",\"mol2\");\n",
       "\tviewer_1729633361288349.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n",
       "\tviewer_1729633361288349.setHoverable({},true,\"\\n        function(atom,viewer,event,container) {\\n            if(!atom.label) {\\n                atom.label = viewer.addLabel(atom.elem + '(' + atom.index + ')', {position: atom, backgroundColor: 'silver', fontColor:'black'});\\n            }\\n        }\\n        \",\"\\n        function(atom,viewer) { \\n            if(atom.label) {\\n                viewer.removeLabel(atom.label);\\n                delete atom.label;\\n            }\\n        }\\n        \");\n",
       "\tviewer_1729633361288349.zoomTo();\n",
       "\tviewer_1729633361288349.setBackgroundColor(\"black\");\n",
       "viewer_1729633361288349.render();\n",
       "});\n",
       "</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/3dmoljs_load.v0": "<script>\n            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n                \n                viewer_1729633361288349.render();\n            });\n            </script>",
      "text/html": [
       "<script>\n",
       "            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n",
       "                \n",
       "                viewer_1729633361288349.render();\n",
       "            });\n",
       "            </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "Molecule(name='23', formula='C28 H29 Cl1 F1 N5 O2')"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "with eq_lib.reading():\n",
    "    mol_fail = eq_lib[\"23_eq1\"]\n",
    "\n",
    "# This will rotate the tert-butyl into the correct orientation.\n",
    "mol_fail.rotate_dihedral((50,49,44,43), 0)\n",
    "\n",
    "mol_fail"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "eq_fix = ml.MoleculeLibrary(\"rb_eq_fix.mlib\", readonly=False, overwrite=True)\n",
    "with eq_fix.writing():\n",
    "    eq_fix[\"23_eq1\"] = mol_fail"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================================================================\n",
      "Optimizing the equilibrium structures (again)\n",
      "Submitting jobs: 0it [00:00, ?it/s]\n",
      "Waiting for jobs: 0it [00:00, ?it/s]\n",
      "Finalizing the calculations: 100%|████████████████| 1/1 [00:00<00:00, 36.99it/s]\n"
     ]
    }
   ],
   "source": [
    "!python rb_w3_opt.py"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now that the final optimization is done, we will reassemble the library."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/3dmoljs_load.v0": "<div id=\"3dmolviewer_17296333623158596\"  style=\"position: relative; width: 100%; height: 500px;\">\n        <p id=\"3dmolwarning_17296333623158596\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n        </div>\n<script>\n\nvar loadScriptAsync = function(uri){\n  return new Promise((resolve, reject) => {\n    //this is to ignore the existence of requirejs amd\n    var savedexports, savedmodule;\n    if (typeof exports !== 'undefined') savedexports = exports;\n    else exports = {}\n    if (typeof module !== 'undefined') savedmodule = module;\n    else module = {}\n\n    var tag = document.createElement('script');\n    tag.src = uri;\n    tag.async = true;\n    tag.onload = () => {\n        exports = savedexports;\n        module = savedmodule;\n        resolve();\n    };\n  var firstScriptTag = document.getElementsByTagName('script')[0];\n  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n});\n};\n\nif(typeof $3Dmolpromise === 'undefined') {\n$3Dmolpromise = null;\n  $3Dmolpromise = loadScriptAsync('https://cdnjs.cloudflare.com/ajax/libs/3Dmol/2.0.4/3Dmol-min.js');\n}\n\nvar viewer_17296333623158596 = null;\nvar warn = document.getElementById(\"3dmolwarning_17296333623158596\");\nif(warn) {\n    warn.parentNode.removeChild(warn);\n}\n$3Dmolpromise.then(function() {\nviewer_17296333623158596 = $3Dmol.createViewer(document.getElementById(\"3dmolviewer_17296333623158596\"),{backgroundColor:\"white\"});\nviewer_17296333623158596.zoomTo();\n\tviewer_17296333623158596.addModel(\"@<TRIPOS>MOLECULE\\n23\\n66 70 0 0 0\\nSMALL\\nNO_CHARGES\\n\\n@<TRIPOS>ATOM\\n1 None 3.6123 -6.5313 0.8219 C\\n2 None 4.0711 -5.2240 0.6990 C\\n3 1 3.2087 -4.3269 0.0400 C\\n4 None 2.1747 -4.7497 -0.6841 N\\n5 None 1.8246 -6.0463 -0.7134 C\\n6 None 2.4760 -6.9432 0.1561 C\\n7 None 5.2448 -4.6537 1.3371 C\\n8 None 5.3477 -3.3604 1.5178 N\\n9 None 4.4269 -2.4723 1.0373 C\\n10 2 3.3965 -2.9858 0.1929 N\\n11 None 4.4686 -1.2754 1.2564 O\\n12 None 6.2288 -5.4657 1.8165 N\\n13 None 6.6753 -6.6554 1.0910 C\\n14 None 8.0149 -6.3964 0.4210 C\\n15 None 8.9814 -5.9598 1.4106 N\\n16 None 8.5512 -4.7074 2.0196 C\\n17 None 7.2315 -4.9158 2.7496 C\\n18 None 1.8272 -8.5206 0.5398 Cl\\n19 None 0.7060 -6.3789 -1.5901 C\\n20 None -0.3737 -5.4700 -1.7526 C\\n21 None -1.5050 -5.8494 -2.4719 C\\n22 None -1.5467 -7.0724 -3.1092 C\\n23 None -0.4590 -7.9369 -3.0684 C\\n24 None 0.6376 -7.5669 -2.3258 C\\n25 None -0.3615 -4.2406 -1.2152 O\\n26 None 1.7244 -8.3696 -2.3646 F\\n27 None 7.3599 -5.8087 3.9731 C\\n28 None 4.1139 -7.2249 1.4781 H\\n29 None 6.7635 -7.4952 1.7798 H\\n30 None 5.9505 -6.9163 0.3308 H\\n31 None 8.3594 -7.3229 -0.0391 H\\n32 None 7.8597 -5.6579 -0.3836 H\\n33 None 9.8903 -5.8440 0.9835 H\\n34 None 9.3076 -4.3801 2.7318 H\\n35 None 8.4095 -3.9034 1.2831 H\\n36 None 6.8591 -3.9418 3.0468 H\\n37 None -2.3223 -5.1473 -2.5432 H\\n38 None -2.4217 -7.3463 -3.6827 H\\n39 None -0.4436 -8.8665 -3.6164 H\\n40 None 0.5780 -4.0381 -0.9800 H\\n41 None 6.3831 -5.9985 4.4134 H\\n42 None 7.9744 -5.3105 4.7214 H\\n43 None 7.8341 -6.7582 3.7403 H\\n44 3 2.5077 -2.0555 -0.4515 C\\n45 4 1.3819 -1.5007 0.1690 C\\n46 None 0.6619 -0.5851 -0.6104 C\\n47 None 1.0038 -0.2583 -1.9082 C\\n48 None 2.1118 -0.8432 -2.5000 C\\n49 None 2.8574 -1.7354 -1.7591 C\\n50 None 0.8972 -1.7261 1.6110 C\\n51 None 1.4775 -2.9471 2.3282 C\\n52 None -0.6292 -1.9110 1.6254 C\\n53 None 1.2686 -0.4755 2.4214 C\\n54 None -0.2012 -0.1002 -0.1821 H\\n55 None 0.4012 0.4539 -2.4560 H\\n56 None 2.3952 -0.6026 -3.5155 H\\n57 None 3.7376 -2.2014 -2.1800 H\\n58 None 2.5356 -2.8502 2.5420 H\\n59 None 1.3055 -3.8693 1.7781 H\\n60 None 0.9750 -3.0516 3.2887 H\\n61 None -0.9318 -2.7537 1.0072 H\\n62 None -1.1669 -1.0327 1.2800 H\\n63 None -0.9602 -2.1011 2.6454 H\\n64 None 2.3444 -0.3213 2.4178 H\\n65 None 0.9348 -0.5851 3.4539 H\\n66 None 0.7979 0.4158 2.0106 H\\n@<TRIPOS>BOND\\n1 1 2 2\\n2 2 3 1\\n3 3 4 2\\n4 4 5 1\\n5 5 6 2\\n6 6 1 1\\n7 2 7 1\\n8 7 8 2\\n9 8 9 1\\n10 9 10 1\\n11 10 3 1\\n12 9 11 2\\n13 7 12 1\\n14 12 13 1\\n15 13 14 1\\n16 14 15 1\\n17 15 16 1\\n18 16 17 1\\n19 17 12 1\\n20 6 18 1\\n21 5 19 1\\n22 19 20 2\\n23 20 21 1\\n24 21 22 2\\n25 22 23 1\\n26 23 24 2\\n27 24 19 1\\n28 20 25 1\\n29 24 26 1\\n30 17 27 1\\n31 1 28 1\\n32 13 29 1\\n33 13 30 1\\n34 14 31 1\\n35 14 32 1\\n36 15 33 1\\n37 16 34 1\\n38 16 35 1\\n39 17 36 1\\n40 21 37 1\\n41 22 38 1\\n42 23 39 1\\n43 25 40 1\\n44 27 41 1\\n45 27 42 1\\n46 27 43 1\\n47 44 45 2\\n48 45 46 1\\n49 46 47 2\\n50 47 48 1\\n51 48 49 2\\n52 49 44 1\\n53 50 51 1\\n54 50 52 1\\n55 50 53 1\\n56 45 50 1\\n57 10 44 1\\n58 46 54 1\\n59 47 55 1\\n60 48 56 1\\n61 49 57 1\\n62 51 58 1\\n63 51 59 1\\n64 51 60 1\\n65 52 61 1\\n66 52 62 1\\n67 52 63 1\\n68 53 64 1\\n69 53 65 1\\n70 53 66 1\\n\\n\",\"mol2\");\n\tviewer_17296333623158596.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n\tviewer_17296333623158596.setHoverable({},true,\"\\n        function(atom,viewer,event,container) {\\n            if(!atom.label) {\\n                atom.label = viewer.addLabel(atom.elem + '(' + atom.index + ')', {position: atom, backgroundColor: 'silver', fontColor:'black'});\\n            }\\n        }\\n        \",\"\\n        function(atom,viewer) { \\n            if(atom.label) {\\n                viewer.removeLabel(atom.label);\\n                delete atom.label;\\n            }\\n        }\\n        \");\n\tviewer_17296333623158596.zoomTo();\n\tviewer_17296333623158596.setBackgroundColor(\"black\");\nviewer_17296333623158596.render();\n});\n</script>",
      "text/html": [
       "<div id=\"3dmolviewer_17296333623158596\"  style=\"position: relative; width: 100%; height: 500px;\">\n",
       "        <p id=\"3dmolwarning_17296333623158596\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n",
       "        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n",
       "        </div>\n",
       "<script>\n",
       "\n",
       "var loadScriptAsync = function(uri){\n",
       "  return new Promise((resolve, reject) => {\n",
       "    //this is to ignore the existence of requirejs amd\n",
       "    var savedexports, savedmodule;\n",
       "    if (typeof exports !== 'undefined') savedexports = exports;\n",
       "    else exports = {}\n",
       "    if (typeof module !== 'undefined') savedmodule = module;\n",
       "    else module = {}\n",
       "\n",
       "    var tag = document.createElement('script');\n",
       "    tag.src = uri;\n",
       "    tag.async = true;\n",
       "    tag.onload = () => {\n",
       "        exports = savedexports;\n",
       "        module = savedmodule;\n",
       "        resolve();\n",
       "    };\n",
       "  var firstScriptTag = document.getElementsByTagName('script')[0];\n",
       "  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n",
       "});\n",
       "};\n",
       "\n",
       "if(typeof $3Dmolpromise === 'undefined') {\n",
       "$3Dmolpromise = null;\n",
       "  $3Dmolpromise = loadScriptAsync('https://cdnjs.cloudflare.com/ajax/libs/3Dmol/2.0.4/3Dmol-min.js');\n",
       "}\n",
       "\n",
       "var viewer_17296333623158596 = null;\n",
       "var warn = document.getElementById(\"3dmolwarning_17296333623158596\");\n",
       "if(warn) {\n",
       "    warn.parentNode.removeChild(warn);\n",
       "}\n",
       "$3Dmolpromise.then(function() {\n",
       "viewer_17296333623158596 = $3Dmol.createViewer(document.getElementById(\"3dmolviewer_17296333623158596\"),{backgroundColor:\"white\"});\n",
       "viewer_17296333623158596.zoomTo();\n",
       "\tviewer_17296333623158596.addModel(\"@<TRIPOS>MOLECULE\\n23\\n66 70 0 0 0\\nSMALL\\nNO_CHARGES\\n\\n@<TRIPOS>ATOM\\n1 None 3.6123 -6.5313 0.8219 C\\n2 None 4.0711 -5.2240 0.6990 C\\n3 1 3.2087 -4.3269 0.0400 C\\n4 None 2.1747 -4.7497 -0.6841 N\\n5 None 1.8246 -6.0463 -0.7134 C\\n6 None 2.4760 -6.9432 0.1561 C\\n7 None 5.2448 -4.6537 1.3371 C\\n8 None 5.3477 -3.3604 1.5178 N\\n9 None 4.4269 -2.4723 1.0373 C\\n10 2 3.3965 -2.9858 0.1929 N\\n11 None 4.4686 -1.2754 1.2564 O\\n12 None 6.2288 -5.4657 1.8165 N\\n13 None 6.6753 -6.6554 1.0910 C\\n14 None 8.0149 -6.3964 0.4210 C\\n15 None 8.9814 -5.9598 1.4106 N\\n16 None 8.5512 -4.7074 2.0196 C\\n17 None 7.2315 -4.9158 2.7496 C\\n18 None 1.8272 -8.5206 0.5398 Cl\\n19 None 0.7060 -6.3789 -1.5901 C\\n20 None -0.3737 -5.4700 -1.7526 C\\n21 None -1.5050 -5.8494 -2.4719 C\\n22 None -1.5467 -7.0724 -3.1092 C\\n23 None -0.4590 -7.9369 -3.0684 C\\n24 None 0.6376 -7.5669 -2.3258 C\\n25 None -0.3615 -4.2406 -1.2152 O\\n26 None 1.7244 -8.3696 -2.3646 F\\n27 None 7.3599 -5.8087 3.9731 C\\n28 None 4.1139 -7.2249 1.4781 H\\n29 None 6.7635 -7.4952 1.7798 H\\n30 None 5.9505 -6.9163 0.3308 H\\n31 None 8.3594 -7.3229 -0.0391 H\\n32 None 7.8597 -5.6579 -0.3836 H\\n33 None 9.8903 -5.8440 0.9835 H\\n34 None 9.3076 -4.3801 2.7318 H\\n35 None 8.4095 -3.9034 1.2831 H\\n36 None 6.8591 -3.9418 3.0468 H\\n37 None -2.3223 -5.1473 -2.5432 H\\n38 None -2.4217 -7.3463 -3.6827 H\\n39 None -0.4436 -8.8665 -3.6164 H\\n40 None 0.5780 -4.0381 -0.9800 H\\n41 None 6.3831 -5.9985 4.4134 H\\n42 None 7.9744 -5.3105 4.7214 H\\n43 None 7.8341 -6.7582 3.7403 H\\n44 3 2.5077 -2.0555 -0.4515 C\\n45 4 1.3819 -1.5007 0.1690 C\\n46 None 0.6619 -0.5851 -0.6104 C\\n47 None 1.0038 -0.2583 -1.9082 C\\n48 None 2.1118 -0.8432 -2.5000 C\\n49 None 2.8574 -1.7354 -1.7591 C\\n50 None 0.8972 -1.7261 1.6110 C\\n51 None 1.4775 -2.9471 2.3282 C\\n52 None -0.6292 -1.9110 1.6254 C\\n53 None 1.2686 -0.4755 2.4214 C\\n54 None -0.2012 -0.1002 -0.1821 H\\n55 None 0.4012 0.4539 -2.4560 H\\n56 None 2.3952 -0.6026 -3.5155 H\\n57 None 3.7376 -2.2014 -2.1800 H\\n58 None 2.5356 -2.8502 2.5420 H\\n59 None 1.3055 -3.8693 1.7781 H\\n60 None 0.9750 -3.0516 3.2887 H\\n61 None -0.9318 -2.7537 1.0072 H\\n62 None -1.1669 -1.0327 1.2800 H\\n63 None -0.9602 -2.1011 2.6454 H\\n64 None 2.3444 -0.3213 2.4178 H\\n65 None 0.9348 -0.5851 3.4539 H\\n66 None 0.7979 0.4158 2.0106 H\\n@<TRIPOS>BOND\\n1 1 2 2\\n2 2 3 1\\n3 3 4 2\\n4 4 5 1\\n5 5 6 2\\n6 6 1 1\\n7 2 7 1\\n8 7 8 2\\n9 8 9 1\\n10 9 10 1\\n11 10 3 1\\n12 9 11 2\\n13 7 12 1\\n14 12 13 1\\n15 13 14 1\\n16 14 15 1\\n17 15 16 1\\n18 16 17 1\\n19 17 12 1\\n20 6 18 1\\n21 5 19 1\\n22 19 20 2\\n23 20 21 1\\n24 21 22 2\\n25 22 23 1\\n26 23 24 2\\n27 24 19 1\\n28 20 25 1\\n29 24 26 1\\n30 17 27 1\\n31 1 28 1\\n32 13 29 1\\n33 13 30 1\\n34 14 31 1\\n35 14 32 1\\n36 15 33 1\\n37 16 34 1\\n38 16 35 1\\n39 17 36 1\\n40 21 37 1\\n41 22 38 1\\n42 23 39 1\\n43 25 40 1\\n44 27 41 1\\n45 27 42 1\\n46 27 43 1\\n47 44 45 2\\n48 45 46 1\\n49 46 47 2\\n50 47 48 1\\n51 48 49 2\\n52 49 44 1\\n53 50 51 1\\n54 50 52 1\\n55 50 53 1\\n56 45 50 1\\n57 10 44 1\\n58 46 54 1\\n59 47 55 1\\n60 48 56 1\\n61 49 57 1\\n62 51 58 1\\n63 51 59 1\\n64 51 60 1\\n65 52 61 1\\n66 52 62 1\\n67 52 63 1\\n68 53 64 1\\n69 53 65 1\\n70 53 66 1\\n\\n\",\"mol2\");\n",
       "\tviewer_17296333623158596.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n",
       "\tviewer_17296333623158596.setHoverable({},true,\"\\n        function(atom,viewer,event,container) {\\n            if(!atom.label) {\\n                atom.label = viewer.addLabel(atom.elem + '(' + atom.index + ')', {position: atom, backgroundColor: 'silver', fontColor:'black'});\\n            }\\n        }\\n        \",\"\\n        function(atom,viewer) { \\n            if(atom.label) {\\n                viewer.removeLabel(atom.label);\\n                delete atom.label;\\n            }\\n        }\\n        \");\n",
       "\tviewer_17296333623158596.zoomTo();\n",
       "\tviewer_17296333623158596.setBackgroundColor(\"black\");\n",
       "viewer_17296333623158596.render();\n",
       "});\n",
       "</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/3dmoljs_load.v0": "<script>\n            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n                \n                viewer_17296333623158596.render();\n            });\n            </script>",
      "text/html": [
       "<script>\n",
       "            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n",
       "                \n",
       "                viewer_17296333623158596.render();\n",
       "            });\n",
       "            </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/3dmoljs_load.v0": "<script>\n            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n                \tviewer_17296333623158596.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n\n                viewer_17296333623158596.render();\n            });\n            </script>",
      "text/html": [
       "<script>\n",
       "            $3Dmolpromise.then(function() { //wrap in promise for non-interactive functionality\n",
       "                \tviewer_17296333623158596.setStyle({\"stick\": {\"radius\": 0.1}, \"sphere\": {\"scale\": 0.15}});\n",
       "\n",
       "                viewer_17296333623158596.render();\n",
       "            });\n",
       "            </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "eq_fix_g1 = ml.MoleculeLibrary(\"rb_eq_fix_g1.mlib\")\n",
    "rb_eq_g1 = ml.MoleculeLibrary(\"rb_eq_g1.mlib\")\n",
    "rb_eq_g2 = ml.MoleculeLibrary(\"rb_eq_g2.mlib\", readonly=False, overwrite=True)\n",
    "\n",
    "with eq_fix_g1.reading(), rb_eq_g1.reading(), rb_eq_g2.writing():\n",
    "    for k in rb_eq_g1.keys():\n",
    "        if k in eq_fix_g1:\n",
    "            rb_eq_g2[k] = eq_fix_g1[k]\n",
    "        else:\n",
    "            rb_eq_g2[k] = rb_eq_g1[k]\n",
    "\n",
    "%mlib_view rb_eq_g2.mlib 23_eq1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>barrier (R-&gt;TS)</th>\n",
       "      <th>barrier (S-&gt;TS)</th>\n",
       "      <th>TS low freq</th>\n",
       "      <th>TS N imag freq</th>\n",
       "      <th>EQ1 N imag freq</th>\n",
       "      <th>EQ2 N imag freq</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>108.3</td>\n",
       "      <td>106.7</td>\n",
       "      <td>-32.2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>103.2</td>\n",
       "      <td>102.6</td>\n",
       "      <td>-36.5</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>141.0</td>\n",
       "      <td>133.3</td>\n",
       "      <td>-48.3</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>150.0</td>\n",
       "      <td>151.9</td>\n",
       "      <td>-30.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>146.1</td>\n",
       "      <td>148.4</td>\n",
       "      <td>-35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>92.6</td>\n",
       "      <td>89.4</td>\n",
       "      <td>-27.8</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>73.7</td>\n",
       "      <td>76.0</td>\n",
       "      <td>-38.6</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>69.9</td>\n",
       "      <td>69.2</td>\n",
       "      <td>-35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>101.3</td>\n",
       "      <td>103.8</td>\n",
       "      <td>-25.5</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    barrier (R->TS)  barrier (S->TS)  TS low freq  TS N imag freq  \\\n",
       "18            108.3            106.7        -32.2               1   \n",
       "22            103.2            102.6        -36.5               1   \n",
       "23            141.0            133.3        -48.3               1   \n",
       "24            150.0            151.9        -30.0               1   \n",
       "25            146.1            148.4        -35.0               1   \n",
       "26             92.6             89.4        -27.8               1   \n",
       "27             73.7             76.0        -38.6               1   \n",
       "28             69.9             69.2        -35.0               1   \n",
       "29            101.3            103.8        -25.5               1   \n",
       "\n",
       "    EQ1 N imag freq  EQ2 N imag freq  \n",
       "18                0                0  \n",
       "22                0                0  \n",
       "23                0                0  \n",
       "24                0                0  \n",
       "25                0                0  \n",
       "26                0                0  \n",
       "27                0                0  \n",
       "28                0                0  \n",
       "29                0                0  "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ts_lib = ml.MoleculeLibrary(\"rb_ts_g3.mlib\")\n",
    "eq_lib = ml.MoleculeLibrary(\"rb_eq_g2.mlib\")\n",
    "\n",
    "with ts_lib.reading(), eq_lib.reading():\n",
    "    data = {}\n",
    "    for key in sorted(ts_lib.keys()):\n",
    "        ts = ts_lib[key]\n",
    "        ts_freq = ts.attrib[\"ORCA/THERMOCHEMISTRY_Energies\"][\"Vibrational frequencies\"]\n",
    "        G_ts = ts.attrib[\"ORCA/THERMOCHEMISTRY_Energies\"][\"Gibbs Energy (Hartree)\"]\n",
    "\n",
    "        eq1 = eq_lib[key + \"_eq1\"]\n",
    "        G_eq1 = eq1.attrib[\"ORCA/THERMOCHEMISTRY_Energies\"][\n",
    "            \"Gibbs Energy (Hartree)\"\n",
    "        ]\n",
    "        eq1_freq = eq1.attrib[\"ORCA/THERMOCHEMISTRY_Energies\"][\"Vibrational frequencies\"]\n",
    "\n",
    "        eq2 = eq_lib[key + \"_eq2\"]\n",
    "        G_eq2 = eq2.attrib[\"ORCA/THERMOCHEMISTRY_Energies\"][\n",
    "            \"Gibbs Energy (Hartree)\"\n",
    "        ]\n",
    "        eq2_freq = eq2.attrib[\"ORCA/THERMOCHEMISTRY_Energies\"][\"Vibrational frequencies\"]\n",
    "\n",
    "        dG_act1 = 2625.5 * (G_ts - G_eq1) # This is the (R) -> TS barrier\n",
    "        dG_act2 = 2625.5 * (G_ts - G_eq2) # This is the (S) -> TS barrier\n",
    "\n",
    "        nim_eq1 =  np.count_nonzero(eq1_freq < 0)\n",
    "        nim_eq2 =  np.count_nonzero(eq2_freq < 0)\n",
    "        nim_ts =  np.count_nonzero(ts_freq < 0)\n",
    "\n",
    "        data[key] = {\n",
    "            # \"barrier (expt)\": \n",
    "            \"barrier (R->TS)\": dG_act1, \n",
    "            \"barrier (S->TS)\": dG_act2,\n",
    "            \"TS low freq\": ts_freq[6],\n",
    "            \"TS N imag freq\": nim_ts,\n",
    "            \"EQ1 N imag freq\": nim_eq1,\n",
    "            \"EQ2 N imag freq\": nim_eq2 \n",
    "        }\n",
    "        # f\"{key}: Barrier={dG_act1:5.1f} ({dG_act2:5.1f}) kJ/mol, TS low freq: {ts_freq[6]:5.2f}, TS #im freq: {nim_ts}, EQ1 #im freq: {nim_eq1}, EQ2 #im freq: {nim_eq2}\"\n",
    "\n",
    "    ts = ts_lib[\"26\"]\n",
    "\n",
    "pd.DataFrame.from_dict(data=data, orient=\"index\").round(1)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "dev-blake",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
